8144997: "IIOException: Field data is past end-of-stream" when calling TIFFImageReader.read()
authorbpb
Fri, 11 Dec 2015 15:07:35 -0800
changeset 34818 0f8792b2b1dc
parent 34817 9b585ae27455
child 34819 48fe0e42c65d
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
jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFIFD.java
--- 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,