#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 8313053332
commit 9b50601458
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
*/
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);
}

View 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,

View 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.

Binary file not shown.