8144997: "IIOException: Field data is past end-of-stream" when calling TIFFImageReader.read()
Summary: Instead of failing for an IFD entry with bad type or offset, continue with the next entry.
Reviewed-by: prr
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java Fri Dec 11 11:38:18 2015 -0800
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java Fri Dec 11 15:07:35 2015 -0800
@@ -475,9 +475,10 @@
int sizeOfType;
try {
sizeOfType = TIFFTag.getSizeOfType(type);
- } catch (IllegalArgumentException e) {
- throw new IIOException("Illegal type " + type
- + " for tag number " + tagNumber, e);
+ } catch (IllegalArgumentException ignored) {
+ // Continue with the next IFD entry.
+ stream.skipBytes(4);
+ continue;
}
int count = (int)stream.readUnsignedInt();
@@ -524,7 +525,7 @@
// Check whether the the field value is within the stream.
if (haveStreamLength && offset + size > streamLength) {
- throw new IIOException("Field data is past end-of-stream");
+ continue;
}
// Add a TIFFIFDEntry as a placeholder. This avoids a mark,