]> source.dussan.org Git - poi.git/commitdiff
Fix exception for old powerpoint documents without the usual stream name
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 25 Nov 2018 23:01:54 +0000 (23:01 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 25 Nov 2018 23:01:54 +0000 (23:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1847442 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/TestAllFiles.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
test-data/slideshow/keyframes.ppt [deleted file]
test-data/slideshow/keyframes.pptx [new file with mode: 0644]

index 61c47b9e8875e0a8aad7c6e7e62d4a94c5d61cfe..40f19f9c859545b4b342140f1d60c52dedeb0c8f 100644 (file)
@@ -289,6 +289,7 @@ public class TestAllFiles {
         "document/Bug50955.doc",
         "document/57843.doc",
         "slideshow/PPT95.ppt",
+        "slideshow/pp40only.ppt",
         "slideshow/Divino_Revelado.pptx",
         "openxml4j/OPCCompliance_CoreProperties_DCTermsNamespaceLimitedUseFAIL.docx",
         "openxml4j/OPCCompliance_CoreProperties_DoNotUseCompatibilityMarkupFAIL.docx",
index 6e2759972978eac736b2e44c25f08eb909f7f7ec..199a9f6286eab8d4b0f30c7dd68cf46b0b94741a 100644 (file)
@@ -47,7 +47,7 @@ public class TestPPTX2PNG {
     private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
     private static final File basedir = null;
     private static final String files =
-        "53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.ppt";
+        "53446.ppt, alterman_security.ppt, alterman_security.pptx, KEY02.pptx, themes.pptx, backgrounds.pptx, layouts.pptx, sample.pptx, shapes.pptx, 54880_chinese.ppt, keyframes.pptx";
 
         
     
index cedfbb0470845a97c4eaf4e137fbabe13db8db0a..26ba59d2c62c3e009fb3c8ff3394c5b4deee8aeb 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.apache.poi.hslf.record;
 
+import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -143,7 +145,7 @@ public class CurrentUserAtom
                // See how long it is. If it's under 28 bytes long, we can't
                //  read it
                if(_contents.length < 28) {
-                   boolean isPP95 = dir.hasEntry("PP40");
+                   boolean isPP95 = dir.hasEntry(PP95_DOCUMENT);
                    // PPT95 has 4 byte size, then data
                        if (!isPP95 && _contents.length >= 4) {
                                int size = LittleEndian.getInt(_contents);
index ecc360e135f5a6ad301f44a32ea53c22f790df63..2f0a116d6836fd53edfd491323473f97342919f0 100644 (file)
@@ -71,6 +71,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
 
        /** Powerpoint document entry/stream name */
     public static final String POWERPOINT_DOCUMENT = "PowerPoint Document";
+       public static final String PP95_DOCUMENT = "PP40";
 
     enum LoadSavePhase {
         INIT, LOADED
index 6f00755a3d9210506df6edf35a10b9c470640c0c..420ae474840b6d4e94d6a85c5bb7454e607c770e 100644 (file)
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hslf.usermodel;
 
+import static org.apache.poi.hslf.usermodel.HSLFSlideShow.POWERPOINT_DOCUMENT;
+import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
@@ -35,6 +38,7 @@ import java.util.TreeMap;
 import org.apache.poi.POIDocument;
 import org.apache.poi.hslf.exceptions.CorruptPowerPointFileException;
 import org.apache.poi.hslf.exceptions.HSLFException;
+import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
 import org.apache.poi.hslf.record.CurrentUserAtom;
 import org.apache.poi.hslf.record.DocumentEncryptionAtom;
 import org.apache.poi.hslf.record.ExOleObjStg;
@@ -183,13 +187,18 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
      * @throws IOException when the powerpoint can't be read
      */
     private void readPowerPointStream() throws IOException {
+        final DirectoryNode dir = getDirectory();
+
+        if (!dir.hasEntry(POWERPOINT_DOCUMENT) && dir.hasEntry(PP95_DOCUMENT)) {
+            throw new OldPowerPointFormatException("You seem to have supplied a PowerPoint95 file, which isn't supported");
+        }
+
         // Get the main document stream
-        DocumentEntry docProps =
-                (DocumentEntry) getDirectory().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+        DocumentEntry docProps = (DocumentEntry)dir.getEntry(POWERPOINT_DOCUMENT);
 
         // Grab the document stream
         int len = docProps.getSize();
-        try (InputStream is = getDirectory().createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT)) {
+        try (InputStream is = dir.createDocumentInputStream(docProps)) {
             _docstream = IOUtils.toByteArray(is, len);
         }
     }
@@ -665,8 +674,8 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable {
 
         // Write the PPT stream into the POIFS layer
         ByteArrayInputStream bais = new ByteArrayInputStream(_docstream);
-        outFS.createOrUpdateDocument(bais, HSLFSlideShow.POWERPOINT_DOCUMENT);
-        writtenEntries.add(HSLFSlideShow.POWERPOINT_DOCUMENT);
+        outFS.createOrUpdateDocument(bais, POWERPOINT_DOCUMENT);
+        writtenEntries.add(POWERPOINT_DOCUMENT);
 
         currentUser.setEncrypted(encryptedSS.getDocumentEncryptionAtom() != null);
         currentUser.writeToFS(outFS);
diff --git a/test-data/slideshow/keyframes.ppt b/test-data/slideshow/keyframes.ppt
deleted file mode 100644 (file)
index e653d64..0000000
Binary files a/test-data/slideshow/keyframes.ppt and /dev/null differ
diff --git a/test-data/slideshow/keyframes.pptx b/test-data/slideshow/keyframes.pptx
new file mode 100644 (file)
index 0000000..e653d64
Binary files /dev/null and b/test-data/slideshow/keyframes.pptx differ