From 76174aae8273d38e1dead2c37e30b5a51a4db42c Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 10 Mar 2017 20:13:52 +0000 Subject: [PATCH] HSSF: Try to handle cases where the length does not match the actual data while cloning, we see this in some documents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1786431 13f79535-47bb-0310-9956-ffa450edef68 --- src/integrationtest/org/apache/poi/TestAllFiles.java | 8 +++----- src/java/org/apache/poi/hssf/record/CFRule12Record.java | 8 +++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java index af30e69efd..9ebe79d768 100644 --- a/src/integrationtest/org/apache/poi/TestAllFiles.java +++ b/src/integrationtest/org/apache/poi/TestAllFiles.java @@ -177,10 +177,10 @@ public class TestAllFiles { HANDLERS.put("spreadsheet/test_properties1", new NullFileHandler()); } - private static final Set unmodifiableHashSet(String... a) { + private static Set unmodifiableHashSet(String... a) { return Collections.unmodifiableSet(hashSet(a)); } - private static final Set hashSet(String... a) { + private static Set hashSet(String... a) { return new HashSet(Arrays.asList(a)); } @@ -279,12 +279,10 @@ public class TestAllFiles { // sheet cloning errors "spreadsheet/47813.xlsx", "spreadsheet/56450.xls", - "spreadsheet/57231_MixedGasReport.xls", "spreadsheet/OddStyleRecord.xls", "spreadsheet/WithChartSheet.xlsx", "spreadsheet/chart_sheet.xlsx", - "spreadsheet/SimpleScatterChart.xlsx", - "spreadsheet/ConditionalFormattingSamples.xls" + "spreadsheet/SimpleScatterChart.xlsx" ); private static final Set IGNORED = unmodifiableHashSet( diff --git a/src/java/org/apache/poi/hssf/record/CFRule12Record.java b/src/java/org/apache/poi/hssf/record/CFRule12Record.java index d9d9793e9b..b10c19a99e 100644 --- a/src/java/org/apache/poi/hssf/record/CFRule12Record.java +++ b/src/java/org/apache/poi/hssf/record/CFRule12Record.java @@ -461,10 +461,12 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord, Cl rec.futureHeader.setAssociatedRange(futureHeader.getAssociatedRange().copy()); super.copyTo(rec); - - rec.ext_formatting_length = ext_formatting_length; + + // use min() to gracefully handle cases where the length-property and the array-lenght do not match + // we saw some such files in circulation + rec.ext_formatting_length = Math.min(ext_formatting_length, ext_formatting_data.length); rec.ext_formatting_data = new byte[ext_formatting_length]; - System.arraycopy(ext_formatting_data, 0, rec.ext_formatting_data, 0, ext_formatting_length); + System.arraycopy(ext_formatting_data, 0, rec.ext_formatting_data, 0, rec.ext_formatting_length); rec.formula_scale = formula_scale.copy();