From 93b1f0664c3123734f0676aba660eedbed451c9c Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Fri, 14 Jul 2017 13:54:06 +0000 Subject: [PATCH] bug 61286/bug 61287 -- allow WriteProtectRecord to have 2 bytes, and allow for HeaderFooter to be empty. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1801966 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/HeaderFooterBase.java | 7 +++++++ .../poi/hssf/record/WriteProtectRecord.java | 3 +++ .../org/apache/poi/hssf/usermodel/TestBugs.java | 13 +++++++++++-- test-data/spreadsheet/61287.xls | Bin 0 -> 11776 bytes 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/61287.xls diff --git a/src/java/org/apache/poi/hssf/record/HeaderFooterBase.java b/src/java/org/apache/poi/hssf/record/HeaderFooterBase.java index 53d5f4692..d0e23c73b 100644 --- a/src/java/org/apache/poi/hssf/record/HeaderFooterBase.java +++ b/src/java/org/apache/poi/hssf/record/HeaderFooterBase.java @@ -36,6 +36,13 @@ public abstract class HeaderFooterBase extends StandardRecord { protected HeaderFooterBase(RecordInputStream in) { if (in.remaining() > 0) { int field_1_footer_len = in.readShort(); + //61287 -- if the footer_len == 0, there may not be a multibyte flag + if (field_1_footer_len == 0) { + field_3_text = ""; + if (in.remaining() == 0) { + return; + } + } field_2_hasMultibyte = in.readByte() != 0x00; if (field_2_hasMultibyte) { diff --git a/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java b/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java index 14afeedc3..e958adb5e 100644 --- a/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java +++ b/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java @@ -37,6 +37,9 @@ public final class WriteProtectRecord extends StandardRecord { */ public WriteProtectRecord(RecordInputStream in) { + if (in.remaining() == 2) { + in.readShort(); + } } public String toString() diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index d4abaf59a..54b8f4a96 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -26,6 +26,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -43,8 +44,6 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; -import javax.imageio.ImageIO; - import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -3096,4 +3095,14 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.getCreationHelper().createFormulaEvaluator().evaluateAll(); wb.close(); } + + @Test + public void test61287() throws IOException { + final Workbook wb = HSSFTestDataSamples.openSampleWorkbook("61287.xls"); + ExcelExtractor ex = new ExcelExtractor((HSSFWorkbook)wb); + String text = ex.getText(); + assertContains(text, "资产负债表"); + wb.close(); + } + } diff --git a/test-data/spreadsheet/61287.xls b/test-data/spreadsheet/61287.xls new file mode 100644 index 0000000000000000000000000000000000000000..4d35295e35087c0dce61e406443b219426693d92 GIT binary patch literal 11776 zcmeHNdyJIT6+hoRc4uLC**CDy+1IzTym57T2|K(MVfG~gU0BxD-Gzcm6i~3rP@rOA zgZKcJwwjGb)LONPX|b^p?LW5C_(-Z)`^Taojj;xe)mSQ>{?55~zL`4@Vq;=r+i&uH z-@WIabAI>S$GPX;Z{B!4e`NTVrDrMOnn!N>S0sxv;^-FAe9M(bD33%q9er~er2k*v zp%%D^x^n-y(RUu)UfkU0nYewpvv7~XJsNj5?i}2?xX0ke5TJbA1-J`w7vV0(&HDa- zeK%U5gKoiZEBR?L-Hi9Gv;#f(^{*0)n5dk|l;^Wj`l8|y|3mcrZ~TfYtZ^OwN&(Ti*(YMWS} zWO}@wcz&k)NZFN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