]> source.dussan.org Git - poi.git/commitdiff
Bug 64130 -- handle empty worksheet names in OldSheetRecord more robustly.
authorTim Allison <tallison@apache.org>
Mon, 10 Feb 2020 17:38:29 +0000 (17:38 +0000)
committerTim Allison <tallison@apache.org>
Mon, 10 Feb 2020 17:38:29 +0000 (17:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873863 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/TestAllFiles.java
src/java/org/apache/poi/hssf/record/OldSheetRecord.java
src/testcases/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java
src/testcases/org/apache/poi/hssf/dev/TestFormulaViewer.java
src/testcases/org/apache/poi/hssf/dev/TestReSave.java
src/testcases/org/apache/poi/hssf/dev/TestRecordLister.java
src/testcases/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
test-data/spreadsheet/64130.xls [new file with mode: 0644]

index 8f9ba82a4c18781b9f26c8687845e6b277dca9c7..7a573981b5d28465dbda4dc6561a2845ddbdcc2c 100644 (file)
@@ -327,6 +327,7 @@ public class TestAllFiles {
         "spreadsheet/testEXCEL_95.xls",
         "spreadsheet/59074.xls",
         "spreadsheet/60284.xls",
+        "spreadsheet/64130.xls",
 
         // OOXML Strict is not yet supported, see bug #57699
         "spreadsheet/SampleSS.strict.xlsx",
index 6c0e81c6fbd5cdc9c7f00b0a927543e52feed8ec..2abec6cb8c103804639e32a84beced2d90f57898 100644 (file)
@@ -47,15 +47,17 @@ public final class OldSheetRecord {
         field_2_visibility = in.readUByte();
         field_3_type = in.readUByte();
         int field_4_sheetname_length = in.readUByte();
-        in.mark(1);
-        byte b = in.readByte();
-        // if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
-        // fail with a LeftOverDataException
-        if (b != 0) {
-            try {
-                in.reset();
-            } catch (IOException e) {
-                throw new RecordFormatException(e);
+        if (field_4_sheetname_length > 0) {
+            in.mark(1);
+            byte b = in.readByte();
+            // if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
+            // fail with a LeftOverDataException
+            if (b != 0) {
+                try {
+                    in.reset();
+                } catch (IOException e) {
+                    throw new RecordFormatException(e);
+                }
             }
         }
         field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
index f493036cf3450591ba8023c14f66f520615142b0..17b43f0da13f477984bbaaf64bc14ea8ca4c339f 100644 (file)
@@ -45,6 +45,7 @@ public class TestBiffDrawingToXml extends BaseXLSIteratingTest {
         EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
         EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
         EXCLUDED.put("61300.xls", RecordFormatException.class);
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); // BIFF 5
     }
        
        @Override
index a62431bc5525925f4acb9e704c34ace7bfc010c2..82a46327b980bbe89e919dd1befc7d7265cea444 100644 (file)
@@ -54,6 +54,7 @@ public class TestBiffViewer extends BaseXLSIteratingTest {
         EXCLUDED.put("50833.xls", IllegalArgumentException.class);       // "Name is too long" when setting username
         EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
         EXCLUDED.put("61300.xls", RecordFormatException.class);
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
     }
 
     @Override
index 3daf938d5c3361ea0da58ee98d88d5f1507cbeca..a24b4967f73ca7077838cf74a729ec85d08e4b90 100644 (file)
@@ -47,6 +47,7 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest {
         EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
         EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
         EXCLUDED.put("61300.xls", RecordFormatException.class);
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
     }
        
        @Override
index e94d55ddfb170089f4373a77560a40a6c70df777..ec69abb4cb4d80b2fcfc9c27cb29fa09409de339 100644 (file)
@@ -47,6 +47,7 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
         EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
         EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
         EXCLUDED.put("61300.xls", RecordFormatException.class);
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
     }
        
     @Override
index a8d59873e1ab2a5e137e1e090b3edc5808086bf0..97b84e21acdb7c0dd331dc007b9ed6ebeeba47d2 100644 (file)
@@ -51,6 +51,7 @@ public class TestReSave extends BaseXLSIteratingTest {
         EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
         EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
         EXCLUDED.put("61300.xls", RecordFormatException.class);
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
     }
 
        @Override
index ec7cd8c08706036ffa7b3d561045fc96a5d7cc83..f15801390b64d6ab9b0079017b23c7b33aefba9b 100644 (file)
@@ -38,7 +38,7 @@ public class TestRecordLister extends BaseXLSIteratingTest {
         EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
         EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
         EXCLUDED.put("61300.xls", RecordFormatException.class);
-
+        EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
     }
        
        @Override
index 1ce8a92c22c611fc24eccf3e2214904f46fe5472..6403fe4e7483da8a7806aa38ba187f681af48872 100644 (file)
@@ -267,6 +267,10 @@ public final class TestOldExcelExtractor {
 
     @Test
     public void testInputStreamNPOIHeader() throws IOException {
+        //TODO: the worksheet names are currently mangled.  They're treated
+        //as if UTF-16, but they're just ascii.  Need to fix this.
+        //Is it possible that the leading 0 byte in the worksheet name is a signal
+        //that these worksheet names should be interpreted as ascii/1252?
         File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
         try (InputStream stream = new FileInputStream(file);
              OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
@@ -350,6 +354,17 @@ public final class TestOldExcelExtractor {
         }
     }
 
+    @Test
+    public void testSheetWithNoName() throws IOException {
+        File file = HSSFTestDataSamples.getSampleFile("64130.xls");
+
+        try (OldExcelExtractor ex = new OldExcelExtractor(file)) {
+            assertEquals(5, ex.getBiffVersion());
+            assertEquals(5, ex.getFileType());
+            assertContains(ex.getText(), "Dawn");
+        }
+    }
+
     private static class NoExitSecurityManager extends SecurityManager {
         @Override
         public void checkPermission(Permission perm) {
diff --git a/test-data/spreadsheet/64130.xls b/test-data/spreadsheet/64130.xls
new file mode 100644 (file)
index 0000000..9d7d42d
Binary files /dev/null and b/test-data/spreadsheet/64130.xls differ