Merge pull request #368 from Schmidor/invalidIDFpointer

An invalid IFD pointer caused creating an empty IFD Directory
This commit is contained in:
Harald Kuhr 2018-01-17 18:18:05 +01:00 committed by GitHub
commit 3f06bbee99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -153,10 +153,13 @@ public final class TIFFReader extends MetadataReader {
CompoundDirectory next = (CompoundDirectory) readDirectory(pInput, nextOffset, true); CompoundDirectory next = (CompoundDirectory) readDirectory(pInput, nextOffset, true);
for (int i = 0; i < next.directoryCount(); i++) { for (int i = 0; i < next.directoryCount(); i++) {
if(next.getDirectory(i).size() > 0) {
// Linked directories might be empty if nextOffset is after EOF, so skip them
ifds.add((IFD) next.getDirectory(i)); ifds.add((IFD) next.getDirectory(i));
} }
} }
} }
}
// TODO: Consider leaving to client code what sub-IFDs to parse (but always parse TAG_SUB_IFD). // TODO: Consider leaving to client code what sub-IFDs to parse (but always parse TAG_SUB_IFD).
readSubdirectories(pInput, entries, readSubdirectories(pInput, entries,

View File

@ -311,4 +311,13 @@ public class TIFFReaderTest extends MetadataReaderAbstractTest {
assertTrue(directory.getEntryById(32934).getValue() instanceof EOFException); assertTrue(directory.getEntryById(32934).getValue() instanceof EOFException);
} }
} }
@Test
public void testReadIDFPointerBeyondEOF() throws IOException {
try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/tiff/ifd-end-pointer.tif"))) {
CompoundDirectory directory = (CompoundDirectory) createReader().read(stream);
assertEquals(1, directory.directoryCount());
assertEquals(15, directory.size());
}
}
} }