This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 224662681f XMLSlideShow.findPictureData: compare data, not just the
CRC32 (#1486)
224662681f is described below
commit 224662681f4ed320e4853741a649d37199334b27
Author: Nayyar <[email protected]>
AuthorDate: Mon Oct 26 23:00:02 2026 +0530
XMLSlideShow.findPictureData: compare data, not just the CRC32 (#1486)
---
.../org/apache/poi/xslf/usermodel/XMLSlideShow.java | 3 ++-
.../poi/xslf/usermodel/TestXSLFSlideShow.java | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git
a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index fa9774daeb..8b711446f7 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -654,7 +654,8 @@ public class XMLSlideShow extends POIXMLDocument
LittleEndian.putLong(cs, 0, checksum);
for (XSLFPictureData pic : getPictureData()) {
- if (Arrays.equals(pic.getChecksum(), cs)) {
+ // the checksum is only a CRC32, so compare the data as well
+ if (Arrays.equals(pic.getChecksum(), cs) &&
Arrays.equals(pic.getData(), pictureData)) {
return pic;
}
}
diff --git
a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
index 312c804a3f..27b45f5afa 100644
---
a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
+++
b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFSlideShow.java
@@ -20,6 +20,7 @@ import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.regex.Pattern;
@@ -30,8 +31,11 @@ import org.apache.poi.sl.usermodel.Placeholder;
import org.apache.poi.xslf.XSLFTestDataSamples;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -421,4 +425,21 @@ class TestXSLFSlideShow {
assertEquals(1, ppt.getFirstSlideNumber());
}
}
+
+ @Test
+ void addPictureWithCollidingChecksum() throws IOException {
+ // "plumless" and "buckeroo" have the same CRC32
+ byte[] data1 = "plumless".getBytes(StandardCharsets.US_ASCII);
+ byte[] data2 = "buckeroo".getBytes(StandardCharsets.US_ASCII);
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFPictureData pic1 = ppt.addPicture(data1,
PictureData.PictureType.PNG);
+ assertSame(pic1, ppt.findPictureData(data1));
+ assertNull(ppt.findPictureData(data2));
+
+ XSLFPictureData pic2 = ppt.addPicture(data2,
PictureData.PictureType.PNG);
+ assertNotSame(pic1, pic2);
+ assertArrayEquals(data2, pic2.getData());
+ assertEquals(2, ppt.getPictureData().size());
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]