]> source.dussan.org Git - poi.git/commitdiff
bug 62592 -- prevent StackOverflowError on corrupt thmx
authorTim Allison <tallison@apache.org>
Wed, 8 Aug 2018 16:06:18 +0000 (16:06 +0000)
committerTim Allison <tallison@apache.org>
Wed, 8 Aug 2018 16:06:18 +0000 (16:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1837658 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
test-data/openxml4j/62592.thmx [new file with mode: 0644]

index 40fc2139f5d99e7f9d19426fccb1f41c3a92c125..975e21d9815c231677a5f76e6457f11ac6b3b13d 100644 (file)
@@ -250,6 +250,9 @@ public final class ZipPackage extends OPCPackage {
         final ZipArchiveEntry contentTypeEntry =
                 zipArchive.getEntry(CONTENT_TYPES_PART_NAME);
         if (contentTypeEntry != null) {
+            if (this.contentTypeManager != null) {
+                throw new InvalidFormatException("ContentTypeManager can only be created once. This must be a cyclic relation?");
+            }
             try {
                 this.contentTypeManager = new ZipContentTypeManager(
                         zipArchive.getInputStream(contentTypeEntry), this);
index a92906b7651091fadcf06bce90a03cdc5359e2ad..ad7fe80c84ab10ed1dba5d5360dc9206f4fb0e2b 100644 (file)
@@ -1090,6 +1090,21 @@ public final class TestPackage {
                openInvalidFile("SampleSS.txt", true);
        }
 
+       @Test(expected = InvalidFormatException.class)
+       public void testBug62592() throws Exception {
+               InputStream is = OpenXML4JTestDataSamples.openSampleStream("62592.thmx");
+               OPCPackage p = OPCPackage.open(is);
+       }
+
+       @Test
+       public void testBug62592SequentialCallsToGetParts() throws Exception {
+               //make absolutely certain that sequential calls don't throw InvalidFormatExceptions
+               String originalFile = OpenXML4JTestDataSamples.getSampleFileName("TestPackageCommon.docx");
+               OPCPackage p2 = OPCPackage.open(originalFile, PackageAccess.READ);
+               p2.getParts();
+               p2.getParts();
+       }
+
        @Test
        public void testDoNotCloseStream() throws IOException {
                OutputStream os = Mockito.mock(OutputStream.class);
diff --git a/test-data/openxml4j/62592.thmx b/test-data/openxml4j/62592.thmx
new file mode 100644 (file)
index 0000000..74489e3
Binary files /dev/null and b/test-data/openxml4j/62592.thmx differ