]> source.dussan.org Git - poi.git/commitdiff
bug 61286/bug 61287 -- allow WriteProtectRecord to have 2 bytes, and allow for Header...
authorTim Allison <tallison@apache.org>
Fri, 14 Jul 2017 13:54:06 +0000 (13:54 +0000)
committerTim Allison <tallison@apache.org>
Fri, 14 Jul 2017 13:54:06 +0000 (13:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1801966 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/HeaderFooterBase.java
src/java/org/apache/poi/hssf/record/WriteProtectRecord.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/61287.xls [new file with mode: 0644]

index 53d5f46926d3cc0f465e4deb98e8a014093d288a..d0e23c73b038149075d6e2ac93bb30347affb472 100644 (file)
@@ -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) {
index 14afeedc37f1e46fe1de69300849a62257783781..e958adb5eb295ecd6bf9c109193dbdae587e9102 100644 (file)
@@ -37,6 +37,9 @@ public final class WriteProtectRecord extends StandardRecord {
      */
     public WriteProtectRecord(RecordInputStream in)
     {
+        if (in.remaining() == 2) {
+            in.readShort();
+        }
     }
 
     public String toString()
index d4abaf59a5f7f2a1544edd89be17b43a5952df5b..54b8f4a96d0c02bede40f0f166deffdd3b9e5641 100644 (file)
@@ -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 (file)
index 0000000..4d35295
Binary files /dev/null and b/test-data/spreadsheet/61287.xls differ