@@ -253,4 +253,55 @@ private void doInlineCcittImage(int width, int height, byte[] ba) throws IOExcep
253253 Assertions .assertEquals (0 , data [i ]);
254254 }
255255 }
256+
257+ /**
258+ * Tests that getDecode() does not throw ClassCastException when the /D parameter
259+ * is a non-array type (e.g., integer). Malformed PDFs may provide an integer or
260+ * other type instead of a COSArray for the Decode parameter.
261+ *
262+ * @throws IOException
263+ */
264+ @ Test
265+ void testGetDecodeWithInvalidType () throws IOException
266+ {
267+ // Test 1: /D set to integer (should return null, not throw ClassCastException)
268+ COSDictionary dict = new COSDictionary ();
269+ dict .setBoolean (COSName .IM , true );
270+ dict .setInt (COSName .W , 1 );
271+ dict .setInt (COSName .H , 1 );
272+ dict .setInt (COSName .BPC , 1 );
273+ dict .setInt (COSName .D , 123 ); // wrong type: integer instead of array
274+
275+ byte [] data = new byte []{0 };
276+ PDInlineImage inlineImage = new PDInlineImage (dict , data , null );
277+ Assertions .assertNull (inlineImage .getDecode (),
278+ "getDecode() should return null for non-array /D value" );
279+
280+ // Test 2: /D set to valid COSArray (should still work)
281+ COSDictionary dict2 = new COSDictionary ();
282+ dict2 .setBoolean (COSName .IM , true );
283+ dict2 .setInt (COSName .W , 1 );
284+ dict2 .setInt (COSName .H , 1 );
285+ dict2 .setInt (COSName .BPC , 1 );
286+ COSArray decodeArray = new COSArray ();
287+ decodeArray .add (COSInteger .ONE );
288+ decodeArray .add (COSInteger .ZERO );
289+ dict2 .setItem (COSName .D , decodeArray );
290+
291+ PDInlineImage inlineImage2 = new PDInlineImage (dict2 , data , null );
292+ Assertions .assertNotNull (inlineImage2 .getDecode (),
293+ "getDecode() should return array for valid /D value" );
294+ Assertions .assertEquals (2 , inlineImage2 .getDecode ().size ());
295+
296+ // Test 3: /D not set (should return null)
297+ COSDictionary dict3 = new COSDictionary ();
298+ dict3 .setBoolean (COSName .IM , true );
299+ dict3 .setInt (COSName .W , 1 );
300+ dict3 .setInt (COSName .H , 1 );
301+ dict3 .setInt (COSName .BPC , 1 );
302+
303+ PDInlineImage inlineImage3 = new PDInlineImage (dict3 , data , null );
304+ Assertions .assertNull (inlineImage3 .getDecode (),
305+ "getDecode() should return null when /D is not set" );
306+ }
256307}
0 commit comments