]> source.dussan.org Git - poi.git/commitdiff
Bug 64132: Fix regression introduced by changing factories
authorDominik Stadler <centic@apache.org>
Mon, 4 Jan 2021 05:51:24 +0000 (05:51 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 4 Jan 2021 05:51:24 +0000 (05:51 +0000)
We need to return EscherBlipRecord for all types in the defined range of recordId,
not UnknownEscherRecord.

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

src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
src/java/org/apache/poi/ddf/EscherBitmapBlip.java
src/java/org/apache/poi/ddf/EscherRecordTypes.java
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
test-data/document/64132.doc [new file with mode: 0644]

index acebed22dc9973e23035f817b3c65e439aad9e91..249e74cb2ef7edf32ad91d5f65cd163e5399199d 100644 (file)
@@ -61,7 +61,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory {
             return EscherContainerRecord::new;
         }
 
-        if (recordTypes.constructor != null) {
+        if (recordTypes.constructor != null && recordTypes != EscherRecordTypes.UNKNOWN) {
             return recordTypes.constructor;
         }
 
index 6fa056b8cd53b922b72befd26d527379e340095e..f6d8aea45a9794e9d3cd96401035429329596f34 100644 (file)
@@ -74,7 +74,7 @@ public class EscherBitmapBlip extends EscherBlipRecord {
 
     @Override
     public int getRecordSize() {
-        return 8 + 16 + 1 + getPicturedata().length;
+        return 8 + 16 + 1 + (getPicturedata() == null ? 0 : getPicturedata().length);
     }
 
     /**
index 53afd2f2b8e13944000d5ec8048c4d741ac785b2..150bb4300bc8ffc001f1d848bd028a5f51937553 100644 (file)
@@ -50,12 +50,12 @@ public enum EscherRecordTypes {
     CLSID(0xf016, null, null, null),
     CALLOUT_RULE(0xf017, null, null, null),
     BLIP_START(0xf018, "Blip", "msofbtBlip", null),
-    BLIP_EMF(0xf018 + 2, "BlipEmf", null, EscherMetafileBlip::new),
-    BLIP_WMF(0xf018 + 3, "BlipWmf", null, EscherMetafileBlip::new),
-    BLIP_PICT(0xf018 + 4, "BlipPict", null, EscherMetafileBlip::new),
-    BLIP_JPEG(0xf018 + 5, "BlipJpeg", null, EscherBitmapBlip::new),
-    BLIP_PNG(0xf018 + 6, "BlipPng", null, EscherBitmapBlip::new),
-    BLIP_DIB(0xf018 + 7, "BlipDib", null, EscherBitmapBlip::new),
+    BLIP_EMF(0xf018 + 2 /* 0xf01a */, "BlipEmf", null, EscherMetafileBlip::new),
+    BLIP_WMF(0xf018 + 3 /* 0xf01b */, "BlipWmf", null, EscherMetafileBlip::new),
+    BLIP_PICT(0xf018 + 4 /* 0xf01c */, "BlipPict", null, EscherMetafileBlip::new),
+    BLIP_JPEG(0xf018 + 5 /* 0xf01d */, "BlipJpeg", null, EscherBitmapBlip::new),
+    BLIP_PNG(0xf018 + 6 /* 0xf01e */, "BlipPng", null, EscherBitmapBlip::new),
+    BLIP_DIB(0xf018 + 7 /* 0xf01f */, "BlipDib", null, EscherBitmapBlip::new),
     BLIP_END(0xf117, "Blip", "msofbtBlip", null),
     REGROUP_ITEMS(0xf118, null, null, null),
     SELECTION(0xf119, null, null, null),
index 89198d27588a9a3fe8ec17a794fe20cdc0988bc5..035e7f0bb095c432ea4dc258d6a293d06eca0a28 100644 (file)
@@ -892,4 +892,14 @@ public class TestBugs{
             assertNotNull(document);
         }
     }
+
+    @Test
+    public void test64132() throws IOException {
+        try(HWPFDocument doc = HWPFTestDataSamples.openSampleFile("64132.doc")) {
+            assertNotNull(doc);
+            PicturesTable picturesTable = doc.getPicturesTable();
+            List<Picture> pictures = picturesTable.getAllPictures();
+            assertNotNull(pictures);
+        }
+    }
 }
diff --git a/test-data/document/64132.doc b/test-data/document/64132.doc
new file mode 100644 (file)
index 0000000..6cce034
Binary files /dev/null and b/test-data/document/64132.doc differ