Author: tilman
Date: Fri Jul 24 10:02:25 2026
New Revision: 1936547
Log:
PDFBOX-5660: add test for readShort, with some inspiration from copilot
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Fri Jul 24 10:02:22 2026 (r1936546)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactory.java
Fri Jul 24 10:02:25 2026 (r1936547)
@@ -513,7 +513,7 @@ public final class CCITTFactory
}
}
- private static int readshort(char endianess, RandomAccess raf) throws
IOException
+ static int readshort(char endianess, RandomAccess raf) throws IOException
{
if (endianess == 'I')
{
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Fri Jul 24 10:02:22 2026 (r1936546)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java
Fri Jul 24 10:02:25 2026 (r1936547)
@@ -354,4 +354,28 @@ public class CCITTFactoryTest extends Te
assertTrue("TIFF LONG must be read as unsigned, not sign-extended",
value >= 0);
raf.close();
}
-}
+
+ public 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
+ {
+ RandomAccess raf = new RandomAccessBuffer(bytes);
+ long value = CCITTFactory.readshort(endianess, raf);
+ assertEquals(expected, value);
+ assertTrue("TIFF SHORT must be read as unsigned, not sign-extended",
value >= 0);
+ raf.close();
+ }
+}
\ No newline at end of file