From 86eeda4cbd9aa07729e5303967e2eb864ea48de5 Mon Sep 17 00:00:00 2001 From: Tim Allison Date: Fri, 13 Jan 2017 20:55:04 +0000 Subject: [PATCH] bug 60584 -- avoid NPE by checking for null/missing image in XSSFReader's getShapes(). git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1778664 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xssf/eventusermodel/XSSFReader.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java index 9dfbf2bfc..e5c9cb25b 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java @@ -37,6 +37,8 @@ import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.SharedStringsTable; import org.apache.poi.xssf.model.StylesTable; @@ -57,6 +59,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument; * for XSSF. */ public class XSSFReader { + + private static final POILogger LOGGER = POILogFactory.getLogger(XSSFReader.class); + private OPCPackage pkg; private PackagePart workbookPart; @@ -318,6 +323,11 @@ public class XSSFReader { PackageRelationship drawings = drawingsList.getRelationship(i); PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI()); PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName); + if (drawingsPart == null) { + //parts can go missing; Excel ignores them silently -- TIKA-2134 + LOGGER.log(POILogger.WARN, "Missing drawing: "+drawingsName +". Skipping it."); + continue; + } XSSFDrawing drawing = new XSSFDrawing(drawingsPart); for (XSSFShape shape : drawing.getShapes()){ shapes.add(shape);