diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index 8b3b980fc8..e2d64f96b0 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -204,7 +204,17 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture { * @return picture data for this shape */ public HSSFPictureData getPictureData(){ - InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook(); + HSSFPatriarch patriarch = getPatriarch(); + HSSFShape parent = getParent(); + while(patriarch == null && parent != null) { + patriarch = parent.getPatriarch(); + parent = parent.getParent(); + } + if(patriarch == null) { + throw new IllegalStateException("Could not find a patriarch for a HSSPicture"); + } + + InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook(); EscherBSERecord bse = iwb.getBSERecord(getPictureIndex()); EscherBlipRecord blipRecord = bse.getBlipRecord(); return new HSSFPictureData(blipRecord); diff --git a/src/ooxml/testcases/org/apache/poi/ss/extractor/TestEmbeddedExtractor.java b/src/ooxml/testcases/org/apache/poi/ss/extractor/TestEmbeddedExtractor.java index c8942965d8..669fd33813 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/extractor/TestEmbeddedExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/ss/extractor/TestEmbeddedExtractor.java @@ -18,6 +18,7 @@ package org.apache.poi.ss.extractor; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.io.InputStream; @@ -30,6 +31,8 @@ import javax.xml.bind.DatatypeConverter; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.POIDataSamples; +import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; @@ -112,4 +115,20 @@ public class TestEmbeddedExtractor { throw new RuntimeException(e); } } + + + @Test + public void testNPE() throws IOException { + HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("angelo.edu_content_files_19555-nsse-2011-multiyear-benchmark.xls"); + EmbeddedExtractor ee = new EmbeddedExtractor(); + + for (Sheet s : wb) { + for (EmbeddedData ed : ee.extractAll(s)) { + assertNotNull(ed.getFilename()); + assertNotNull(ed.getEmbeddedData()); + assertNotNull(ed.getShape()); + } + } + + } } diff --git a/test-data/spreadsheet/angelo.edu_content_files_19555-nsse-2011-multiyear-benchmark.xls b/test-data/spreadsheet/angelo.edu_content_files_19555-nsse-2011-multiyear-benchmark.xls new file mode 100644 index 0000000000..bff2dea560 Binary files /dev/null and b/test-data/spreadsheet/angelo.edu_content_files_19555-nsse-2011-multiyear-benchmark.xls differ