You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2026/01/30 19:58:39 UTC

svn commit: r1931617 - pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image

Author: tilman
Date: Fri Jan 30 19:58:35 2026
New Revision: 1931617

Log:
PDFBOX-5660: add test by by Ze Sheng

Modified:
   pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java	Fri Jan 30 19:58:27 2026	(r1931616)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/PDInlineImageTest.java	Fri Jan 30 19:58:35 2026	(r1931617)
@@ -253,4 +253,55 @@ class PDInlineImageTest
             Assertions.assertEquals(0, data[i]);
         }
     }
+
+    /**
+     * Tests that getDecode() does not throw ClassCastException when the /D parameter
+     * is a non-array type (e.g., integer). Malformed PDFs may provide an integer or
+     * other type instead of a COSArray for the Decode parameter.
+     * 
+     * @throws IOException
+     */
+    @Test
+    void testGetDecodeWithInvalidType() throws IOException
+    {
+        // Test 1: /D set to integer (should return null, not throw ClassCastException)
+        COSDictionary dict = new COSDictionary();
+        dict.setBoolean(COSName.IM, true);
+        dict.setInt(COSName.W, 1);
+        dict.setInt(COSName.H, 1);
+        dict.setInt(COSName.BPC, 1);
+        dict.setInt(COSName.D, 123); // wrong type: integer instead of array
+
+        byte[] data = new byte[]{0};
+        PDInlineImage inlineImage = new PDInlineImage(dict, data, null);
+        Assertions.assertNull(inlineImage.getDecode(),
+                "getDecode() should return null for non-array /D value");
+
+        // Test 2: /D set to valid COSArray (should still work)
+        COSDictionary dict2 = new COSDictionary();
+        dict2.setBoolean(COSName.IM, true);
+        dict2.setInt(COSName.W, 1);
+        dict2.setInt(COSName.H, 1);
+        dict2.setInt(COSName.BPC, 1);
+        COSArray decodeArray = new COSArray();
+        decodeArray.add(COSInteger.ONE);
+        decodeArray.add(COSInteger.ZERO);
+        dict2.setItem(COSName.D, decodeArray);
+
+        PDInlineImage inlineImage2 = new PDInlineImage(dict2, data, null);
+        Assertions.assertNotNull(inlineImage2.getDecode(),
+                "getDecode() should return array for valid /D value");
+        Assertions.assertEquals(2, inlineImage2.getDecode().size());
+
+        // Test 3: /D not set (should return null)
+        COSDictionary dict3 = new COSDictionary();
+        dict3.setBoolean(COSName.IM, true);
+        dict3.setInt(COSName.W, 1);
+        dict3.setInt(COSName.H, 1);
+        dict3.setInt(COSName.BPC, 1);
+
+        PDInlineImage inlineImage3 = new PDInlineImage(dict3, data, null);
+        Assertions.assertNull(inlineImage3.getDecode(),
+                "getDecode() should return null when /D is not set");
+    }
 }