Bug 62592 - StackOverflow on standalone ThemeManager files in 4.0.0-SNAPSHOT
Summary: StackOverflow on standalone ThemeManager files in 4.0.0-SNAPSHOT
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: OPC (show other bugs)
Version: 4.0.x-dev
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-01 16:36 UTC by Tim Allison
Modified: 2018-08-08 16:06 UTC (History)
0 users



Attachments
triggering document (3.58 KB, application/zip)
2018-08-01 16:36 UTC, Tim Allison
Details
First draft patch (2.11 KB, patch)
2018-08-02 14:43 UTC, Tim Allison
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Allison 2018-08-01 16:36:55 UTC
Created attachment 36064 [details]
triggering document

In running 4.0.0-SNAPSHOT against our regression set, I found a SO exception triggered by corrupt files.

Code:
OPCPackage.open(p.toFile());

With 4.0.0-SNAPSHOT, I get:
java.lang.StackOverflowError
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:741)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.<init>(URLClassPath.java:716)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader$3.run(URLClassPath.java:968)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader$3.run(URLClassPath.java:966)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.getResource(URLClassPath.java:965)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.getResource(URLClassPath.java:926)
	at java.base/jdk.internal.loader.URLClassPath$JarLoader.findResource(URLClassPath.java:901)
	at java.base/jdk.internal.loader.URLClassPath.findResource(URLClassPath.java:282)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findResourceOnClassPath(BuiltinClassLoader.java:479)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findResource(BuiltinClassLoader.java:303)
	at java.base/java.lang.ClassLoader.getResource(ClassLoader.java:1400)
	at java.base/java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1736)
	at org.apache.xerces.parsers.SecuritySupport$6.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at org.apache.xerces.parsers.SecuritySupport.getResourceAsStream(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.findJarServiceProvider(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
	at org.apache.poi.ooxml.util.DocumentHelper.newDocumentBuilder(DocumentHelper.java:89)
	at org.apache.poi.ooxml.util.DocumentHelper.readDocument(DocumentHelper.java:147)
...


With POI 3.17, we get:

org.apache.poi.openxml4j.exceptions.InvalidFormatException: The part /_rels/.rels does not have any content type ! Rule: Package require content types when retrieving a part from a package. [M.1.14]

	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:341)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:756)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:298)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:201)
	at
Comment 1 Tim Allison 2018-08-01 16:37:45 UTC
Sorry, SO _error_...of course...
Comment 2 Tim Allison 2018-08-01 16:41:09 UTC
And w Java 8:

java.lang.StackOverflowError
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:868)
	at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:841)
	at sun.misc.URLClassPath$JarLoader$3.run(URLClassPath.java:1094)
	at sun.misc.URLClassPath$JarLoader$3.run(URLClassPath.java:1091)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1090)
	at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1050)
	at sun.misc.URLClassPath$JarLoader.findResource(URLClassPath.java:1020)
	at sun.misc.URLClassPath.findResource(URLClassPath.java:215)
	at java.net.URLClassLoader$2.run(URLClassLoader.java:569)
	at java.net.URLClassLoader$2.run(URLClassLoader.java:567)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findResource(URLClassLoader.java:566)
	at java.lang.ClassLoader.getResource(ClassLoader.java:1096)
	at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:232)
	at org.apache.xerces.parsers.SecuritySupport$6.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.apache.xerces.parsers.SecuritySupport.getResourceAsStream(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.findJarServiceProvider(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
	at org.apache.xerces.parsers.ObjectFactory.createObject(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
	at org.apache.poi.ooxml.util.DocumentHelper.newDocumentBuilder(DocumentHelper.java:89)
	at org.apache.poi.ooxml.util.DocumentHelper.readDocument(DocumentHelper.java:147)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:375)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:100)
	at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:54)
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:255)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
	at org.apache.poi.openxml4j.opc.OPCPackage.getPart(OPCPackage.java:603)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:339)
	at org.apache.poi.openxml4j.opc.ZipPackage$EntryTriple.<init>(ZipPackage.java:317)
	at org.apache.poi.openxml4j.opc.ZipPackage.lambda$getPartsImpl$0(ZipPackage.java:284)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:287)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
	at org.apache.poi.openxml4j.opc.OPCPackage.getPart(OPCPackage.java:603)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:339)
	at org.apache.poi.openxml4j.opc.ZipPackage$EntryTriple.<init>(ZipPackage.java:317)
	at org.apache.poi.openxml4j.opc.ZipPackage.lambda$getPartsImpl$0(ZipPackage.java:284)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
Comment 3 Tim Allison 2018-08-01 16:47:44 UTC
Sorry, the files are not corrupt zip files. I can open them with commons-compress and WinZip...they appear to contain only ThemeManager info...any idea what these are?
Comment 4 Tim Allison 2018-08-02 14:43:00 UTC
Created attachment 36069 [details]
First draft patch

Not sure I like this patch, any recs for a better solution?
Comment 5 PJ Fanning 2018-08-08 11:57:02 UTC
The patch seems ok to me as is.
But one alternative would be just to have a boolean member to keep track of whether the ContentTypeManager has already been created. This could be extended to a map to track other items that we are worried could lead to recursive stack overflows.
Comment 6 Tim Allison 2018-08-08 16:06:58 UTC
r1837658

Thank you, PJ! We can change if needed.