Fix for erroneous encoded ccitt lines

The ccitt tiff is missing a terminating huffman code on a line end. The following EOL is misinterpreted and the codestream read till an ArrayIndexOutOfBoundsException occurs.
Now reading the line is aborted as soon as an EOL is found.
This commit is contained in:
Oliver Schmidtmer 2017-06-07 13:44:49 +02:00
parent 86fa76c17d
commit 4e640dda51
3 changed files with 25 additions and 2 deletions

View File

@ -355,11 +355,14 @@ final class CCITTFaxDecoderStream extends FilterInputStream {
if (n.isLeaf) {
total += n.value;
if (n.value < 64) {
if (n.value >= 64) {
n = tree.root;
}
else if (n.value >= 0) {
return total;
}
else {
n = tree.root;
return columns;
}
}
}

View File

@ -261,4 +261,24 @@ public class CCITTFaxDecoderStreamTest {
byte decoded = (byte) inputStream.read();
assertEquals((byte) 0b10101010, decoded);
}
@Test
public void testG3AOE() throws IOException {
InputStream inputStream = getClass().getResourceAsStream("/tiff/ccitt/g3aoe.tif");
// Skip until StripOffsets: 8
for (int i = 0; i < 8; i++) {
inputStream.read();
}
// Read until StripByteCounts: 20050
byte[] data = new byte[20050];
new DataInputStream(inputStream).readFully(data);
InputStream stream = new CCITTFaxDecoderStream(new ByteArrayInputStream(data),
1728, TIFFExtension.COMPRESSION_CCITT_T4, 1, TIFFExtension.GROUP3OPT_FILLBITS);
byte[] bytes = new byte[216 * 1168]; // 1728 x 1168 pixel, 1 bpp => 216 bytes * 1168
new DataInputStream(stream).readFully(bytes);
}
}