]> source.dussan.org Git - poi.git/commitdiff
Bug 66425: Avoid exceptions found via poi-fuzz
authorDominik Stadler <centic@apache.org>
Sat, 30 Dec 2023 11:11:42 +0000 (11:11 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 30 Dec 2023 11:11:42 +0000 (11:11 +0000)
Prevent ClassCastException

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63504

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1914991 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java
poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls [new file with mode: 0644]
test-data/spreadsheet/stress.xls

index 080938367b1b0fc9d89f8d221633ef55fe230d30..0dc114ac67445bf1dde3fbb141b8361e74909342 100644 (file)
@@ -57,7 +57,11 @@ public class HSSFShapeFactory {
             }
             EscherClientDataRecord clientData = ((EscherContainerRecord) child).getChildById(EscherClientDataRecord.RECORD_ID);
             if (null != clientData) {
-                obj = (ObjRecord) agg.getShapeToObjMapping().get(clientData);
+                Record record = agg.getShapeToObjMapping().get(clientData);
+                if (!(record instanceof ObjRecord)) {
+                    throw new IllegalArgumentException("Had unexpected type of clientData: " + (record == null ? "<null>" : record.getClass()));
+                }
+                obj = (ObjRecord) record;
             }
             HSSFShapeGroup group = new HSSFShapeGroup(container, obj);
             List<EscherContainerRecord> children = container.getChildContainers();
index b9abe815f41fb9938c49f4569b598be5ac0b3a0c..f7af364978efd670bf715489e8d7e57e11bd675b 100644 (file)
@@ -57,6 +57,7 @@ class TestBiffDrawingToXml extends BaseTestIteratingXLS {
         excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls", IllegalArgumentException.class);
         excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5436547081830400.xls", IllegalArgumentException.class);
         excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5889658057523200.xls", IndexOutOfBoundsException.class);
+        excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls", IllegalArgumentException.class);
         return excludes;
     }
 
index e21e359767174ceab2a704a166fea8b242ddd767..12854be9200b6f1817d6e4dcd9a0a7274ae678ea 100644 (file)
@@ -138,7 +138,9 @@ class TestDrawingAggregate {
         File[] files = testData.listFiles((dir, name) -> name.endsWith(".xls"));
         assertNotNull(files, "Need to find files in test-data path, had path: " + testData);
         return Stream.of(files).
-                filter(file -> !file.getName().equals("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls")).
+                filter(file ->
+                        !file.getName().equals("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5285517825277952.xls") &&
+                        !file.getName().equals("clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls")).
                 map(Arguments::of);
     }
 
diff --git a/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls
new file mode 100644 (file)
index 0000000..2240cb1
Binary files /dev/null and b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-4977868385681408.xls differ
index 43e8f6950df06c0b99b5101fae617ea2a07f706a..4a146faa1f53de54d33e403d1daa69b1fe411a16 100644 (file)
Binary files a/test-data/spreadsheet/stress.xls and b/test-data/spreadsheet/stress.xls differ