#62513 - Don't try to parse embedded package relationships

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1834729 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-06-30 11:20:23 +00:00
parent f36a089a09
commit c038ccdd1d
4 changed files with 21 additions and 5 deletions

View File

@ -44,10 +44,13 @@ public abstract class POIXMLFactory {
* @since by POI 3.14-Beta1 * @since by POI 3.14-Beta1
*/ */
public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackagePart part) { public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent, PackagePart part) {
PackageRelationship rel = getPackageRelationship(parent, part); final PackageRelationship rel = getPackageRelationship(parent, part);
POIXMLRelation descriptor = getDescriptor(rel.getRelationshipType()); final String relType = rel.getRelationshipType();
final POIXMLRelation descriptor = getDescriptor(relType);
if (descriptor == null || descriptor.getRelationClass() == null) { // 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()); LOGGER.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
return new POIXMLDocumentPart(parent, part); return new POIXMLDocumentPart(parent, part);
} }

View File

@ -139,6 +139,8 @@ public class XSLFRelation extends POIXMLRelation {
null 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( public static final XSLFRelation WORKBOOK = new XSLFRelation(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
POIXMLDocument.PACK_OBJECT_REL_TYPE, POIXMLDocument.PACK_OBJECT_REL_TYPE,

View File

@ -324,6 +324,17 @@ public final class TestPOIXMLDocument {
} }
} }
@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 @Test
public void testOSGIClassLoading() { public void testOSGIClassLoading() {
// the schema type loader is cached per thread in POIXMLTypeLoader. // the schema type loader is cached per thread in POIXMLTypeLoader.

Binary file not shown.