Author: tilman
Date: Fri Jul 24 10:02:18 2026
New Revision: 1936545
Log:
PDFBOX-5660: add test for readShort, with some inspiration from copilot
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Modified:
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Fri Jul 24 09:26:56 2026 (r1936544)
+++
pdfbox/branches/3.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Fri Jul 24 10:02:18 2026 (r1936545)
@@ -467,7 +467,7 @@ public final class CCITTFactory
}
}
- private static int readshort(char endianess, RandomAccessRead raf) throws
IOException
+ static int readshort(char endianess, RandomAccessRead raf) throws
IOException
{
if (endianess == 'I')
{
Modified:
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
==============================================================================
---
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Fri Jul 24 09:26:56 2026 (r1936544)
+++
pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Fri Jul 24 10:02:18 2026 (r1936545)
@@ -366,4 +366,30 @@ class CCITTFactoryTest
assertTrue(value >= 0, "TIFF LONG must be read as unsigned, not
sign-extended");
}
}
+
+ @Test
+ void testReadShortIsUnsigned() throws IOException
+ {
+ assertReadShortIsUnsigned(65535, new byte[] {(byte) 0xFF, (byte)
0xFF}, 'I');
+ assertReadShortIsUnsigned(128, new byte[] {(byte) 0x80, (byte)
0x00}, 'I');
+ assertReadShortIsUnsigned(32768, new byte[] {(byte) 0x00, (byte)
0x80}, 'I');
+ assertReadShortIsUnsigned(256, new byte[] {(byte) 0x00, (byte)
0x01}, 'I');
+ assertReadShortIsUnsigned(1, new byte[] {(byte) 0x01, (byte)
0x00}, 'I');
+
+ assertReadShortIsUnsigned(65535, new byte[] {(byte) 0xFF, (byte)
0xFF}, 'M');
+ assertReadShortIsUnsigned(128, new byte[] {(byte) 0x00, (byte)
0x80}, 'M');
+ assertReadShortIsUnsigned(32768, new byte[] {(byte) 0x80, (byte)
0x00}, 'M');
+ assertReadShortIsUnsigned(256, new byte[] {(byte) 0x01, (byte)
0x00}, 'M');
+ assertReadShortIsUnsigned(1, new byte[] {(byte) 0x00, (byte)
0x01}, 'M');
+ }
+
+ private static void assertReadShortIsUnsigned(long expected, byte[] bytes,
char endianess) throws IOException
+ {
+ try (RandomAccessRead raf = new RandomAccessReadBuffer(bytes))
+ {
+ long value = CCITTFactory.readshort(endianess, raf);
+ assertEquals(expected, value);
+ assertTrue(value >= 0, "TIFF SHORT must be read as unsigned, not
sign-extended");
+ }
+ }
}
\ No newline at end of file