This is an automated email from the ASF dual-hosted git repository.

jaragunde 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 dfa53082b3 Prevent rendering a bitmap when its effective size is 0. 
(#1179)
dfa53082b3 is described below

commit dfa53082b3e04412a4440c77862f17061cb2e97f
Author: Jacobo Aragunde PĂ©rez <[email protected]>
AuthorDate: Thu Jul 9 15:03:08 2026 +0200

    Prevent rendering a bitmap when its effective size is 0. (#1179)
    
    A width or height of 0, either in the image or the cropping rectangle,
    means that effectively the image won't be rendered. Moreover, sizes of
    0 in the cropping rectangle produce NaN values in the transformation
    matrix, which may crash or produce incorrect behavior depending on the
    Graphics2D implementation. For example, the included test file  will
    produce invalid SVG with Apache Batik's SVGGraphics2D.
---
 .../apache/poi/sl/tests/draw/TestDrawPictureShape.java  |  12 ++++++++++++
 .../org/apache/poi/sl/draw/BitmapImageRenderer.java     |   9 ++++++++-
 test-data/slideshow/crop-to-0.pptx                      | Bin 0 -> 10314 bytes
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git 
a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java
 
b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java
index 0bd9414d8b..a2cf6a01af 100644
--- 
a/poi-ooxml/src/test/java/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java
+++ 
b/poi-ooxml/src/test/java/org/apache/poi/sl/tests/draw/TestDrawPictureShape.java
@@ -147,4 +147,16 @@ class TestDrawPictureShape {
         assertEquals(Transparency.TRANSLUCENT, img.getTransparency());
         assertEquals(color, new Color(img.getRGB(0, 0), true));
     }
+
+    @Test
+    void testCroppedTo0PictureShape() throws IOException {
+        SlideShow<?, ?> ss = openSampleDocument("crop-to-0.pptx");
+
+        // shape in slide 0 is cropped with `<a:srcRect l="60000" t="70000" 
r="40000" b="30000"/>`
+        verifySlideFirstPixelColor(ss.getSlides().get(0), new Color(0, 0, 0, 
0));
+        // shape in slide 1 is cropped with anchor `<a:ext cx="0" cy="0"/>`
+        verifySlideFirstPixelColor(ss.getSlides().get(1), new Color(0, 0, 0, 
0));
+        // shape in slide 2 is uncropped
+        verifySlideFirstPixelColor(ss.getSlides().get(2), new Color(0, 38, 
255, 255));
+    }
 }
diff --git a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java 
b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
index 87775e72d5..0e6e43c2ab 100644
--- a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
+++ b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
@@ -330,9 +330,16 @@ public class BitmapImageRenderer implements ImageRenderer {
         int iw = img.getWidth();
         int ih = img.getHeight();
 
-
         double cw = (100000-clip.left-clip.right) / 100000.0;
         double ch = (100000-clip.top-clip.bottom) / 100000.0;
+
+        if (anchor.getWidth() == 0 || anchor.getHeight() == 0 ||
+                iw == 0 || ih == 0 || cw == 0 || ch == 0) {
+            // If the size of the image, the source rectangle or the anchor is 
0,
+            // we don't need to render anything.
+            return true;
+        }
+
         double sx = anchor.getWidth()/(iw*cw);
         double sy = anchor.getHeight()/(ih*ch);
         double tx = anchor.getX()-(iw*sx*clip.left/100000.0);
diff --git a/test-data/slideshow/crop-to-0.pptx 
b/test-data/slideshow/crop-to-0.pptx
new file mode 100644
index 0000000000..71cdafa21e
Binary files /dev/null and b/test-data/slideshow/crop-to-0.pptx differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to