[bug-69697] HSLF getPictureData can return null for some pictures

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1926414 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2025-06-14 14:14:15 +00:00
parent 2ca7114a8f
commit c01228c331
4 changed files with 22 additions and 16 deletions

View File

@ -576,9 +576,7 @@ public final class HSLFFill {
} else {
EscherBSERecord bse = (EscherBSERecord) bstore.getChild(idx - 1);
for (HSLFPictureData pd : pict) {
// Reference equals is safe because these BSE belong to the same slideshow
if (pd.bse == bse) {
if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}

View File

@ -124,9 +124,7 @@ public class HSLFPictureShape extends HSLFSimpleShape implements PictureShape<HS
LOG.atError().log("no reference to picture data found ");
} else {
for (HSLFPictureData pd : pict) {
// Reference equals is safe because these BSE belong to the same slideshow
if (pd.bse == bse) {
if (pd.getOffset() == bse.getOffset()) {
return pd;
}
}

View File

@ -47,6 +47,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.fonts.FontGroup;
import org.apache.poi.ddf.AbstractEscherOptRecord;
@ -68,19 +69,10 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.macros.VBAMacroReader;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.extractor.SlideShowExtractor;
import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.sl.usermodel.PaintStyle;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.sl.usermodel.TextBox;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.Units;
@ -904,4 +896,22 @@ public final class TestBugs {
assertEquals(ShapeType.NOT_PRIMITIVE, shList.get(2).getShapeType());
}
}
@Test
void test69697() throws Exception {
try (HSLFSlideShow ppt = open("bug69697.ppt")) {
HSLFSlide slide = ppt.getSlides().get(0);
for (HSLFShape sh : slide.getShapes()) {
if (sh instanceof HSLFPictureShape) {
HSLFPictureShape pict = (HSLFPictureShape) sh;
HSLFPictureData pictData = pict.getPictureData();
assertNotNull(pictData, "PictureData should not be null for shape: " + pict.getShapeName());
byte[] data = pictData.getData();
assertNotNull(data, "Picture data should not be null for shape: " + pict.getShapeName());
PictureData.PictureType type = pictData.getType();
assertNotNull(type, "Picture type should not be null for shape: " + pict.getShapeName());
}
}
}
}
}

Binary file not shown.