Author: tallison
Date: Wed Aug  8 16:06:18 2018
New Revision: 1837658

URL: http://svn.apache.org/viewvc?rev=1837658&view=rev
Log:
bug 62592 -- prevent StackOverflowError on corrupt thmx

Added:
    poi/trunk/test-data/openxml4j/62592.thmx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1837658&r1=1837657&r2=1837658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Wed 
Aug  8 16:06:18 2018
@@ -250,6 +250,9 @@ public final class ZipPackage extends OP
         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);

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1837658&r1=1837657&r2=1837658&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java 
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java 
Wed Aug  8 16:06:18 2018
@@ -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);

Added: poi/trunk/test-data/openxml4j/62592.thmx
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/openxml4j/62592.thmx?rev=1837658&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/openxml4j/62592.thmx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to