]> source.dussan.org Git - poi.git/commitdiff
#62513 - Don't try to parse embedded package relationships
authorAndreas Beeker <kiwiwings@apache.org>
Sat, 30 Jun 2018 11:20:23 +0000 (11:20 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sat, 30 Jun 2018 11:20:23 +0000 (11:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1834729 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/ooxml/POIXMLFactory.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
src/ooxml/testcases/org/apache/poi/ooxml/TestPOIXMLDocument.java
test-data/slideshow/bug62513.pptx [new file with mode: 0644]

index ca6cdb30c01f774d9f336a296a3ed77c825e1668..3c88f1fae2fc6dec70b1bda8b4e207de37989324 100644 (file)
@@ -44,10 +44,13 @@ public abstract class POIXMLFactory {
      * @since by POI 3.14-Beta1
      */
     public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackagePart part) {
-        PackageRelationship rel = getPackageRelationship(parent, part);
-        POIXMLRelation descriptor = getDescriptor(rel.getRelationshipType());
-        
-        if (descriptor == null || descriptor.getRelationClass() == null) {
+        final PackageRelationship rel = getPackageRelationship(parent, part);
+        final String relType = rel.getRelationshipType();
+        final POIXMLRelation descriptor = getDescriptor(relType);
+
+        // don't parse the document parts, if its class can't be determined
+        // or if it's a package relation of another embedded resource
+        if (descriptor == null || descriptor.getRelationClass() == null || POIXMLDocument.PACK_OBJECT_REL_TYPE.equals(relType)) {
             LOGGER.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
             return new POIXMLDocumentPart(parent, part);
         }
index 9ac9df3c3029833130354fe2d2a8a661979b87d3..62f009a15ab784036e58e1c6e3f5dac8bcf7c93f 100644 (file)
@@ -139,6 +139,8 @@ public class XSLFRelation extends POIXMLRelation {
             null
     );
 
+    // this is not the same as in XSSFRelation.WORKBOOK, as it is usually used by embedded charts
+    // referencing the original embedded excel workbook
     public static final XSLFRelation WORKBOOK = new XSLFRelation(
             "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
             POIXMLDocument.PACK_OBJECT_REL_TYPE,
index 039169fa2975623f8c3cb2c96cff3e0d5abe049f..056ecbb8e96c8cac013f14fffae989d2d8254fd5 100644 (file)
@@ -323,7 +323,18 @@ public final class TestPOIXMLDocument {
             open.close();
         }
     }
-    
+
+    @Test
+    public void dontParseEmbeddedDocuments() throws IOException {
+        // bug #62513
+        POIDataSamples pds = POIDataSamples.getSlideShowInstance();
+        try (InputStream is = pds.openResourceAsStream("bug62513.pptx");
+            XMLSlideShow ppt = new XMLSlideShow(is)) {
+            POIXMLDocumentPart doc = ppt.getSlides().get(12).getRelationById("rId3");
+            assertEquals(POIXMLDocumentPart.class, doc.getClass());
+        }
+    }
+
     @Test
     public void testOSGIClassLoading() {
         // the schema type loader is cached per thread in POIXMLTypeLoader.
diff --git a/test-data/slideshow/bug62513.pptx b/test-data/slideshow/bug62513.pptx
new file mode 100644 (file)
index 0000000..a65c8e2
Binary files /dev/null and b/test-data/slideshow/bug62513.pptx differ