commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1206412 - in /commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff: TiffField.java TiffReader.java
Date Sat, 26 Nov 2011 09:19:40 GMT
Author: damjan
Date: Sat Nov 26 09:19:39 2011
New Revision: 1206412

URL: http://svn.apache.org/viewvc?rev=1206412&view=rev
Log:
When reading TIFF files (and EXIF sections in JPEG)
that have invalid offsets and/or lengths
for their IFD fields, ignore these
bad IFDs when we are not in strict mode.

This seems to be how other tools handle
this problem; we used to throw IOException
or OutOfMemoryError, and fail to parse the
file with no possibility of recovery.

Jira issue key: SANSELAN-55


Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java?rev=1206412&r1=1206411&r2=1206412&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
Sat Nov 26 09:19:39 2011
@@ -105,7 +105,7 @@ public class TiffField implements TiffCo
         this.oversizeValue = bytes;
     }
 
-    private static FieldType getFieldType(int value)
+    static FieldType getFieldType(int value)
     {
         for (int i = 0; i < FIELD_TYPES.length; i++)
         {
@@ -282,7 +282,7 @@ public class TiffField implements TiffCo
         return result;
     }
 
-    private int getValueLengthInBytes()
+    int getValueLengthInBytes()
     {
         int unit_length = fieldType.length;
         int valueLength = unit_length * length;
@@ -793,4 +793,4 @@ public class TiffField implements TiffCo
     {
         this.sortHint = sortHint;
     }
-}
\ No newline at end of file
+}

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java?rev=1206412&r1=1206411&r2=1206412&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java
Sat Nov 26 09:19:39 2011
@@ -28,6 +28,7 @@ import org.apache.sanselan.common.Binary
 import org.apache.sanselan.common.byteSources.ByteSource;
 import org.apache.sanselan.formats.tiff.TiffDirectory.ImageDataElement;
 import org.apache.sanselan.formats.tiff.constants.TiffConstants;
+import org.apache.sanselan.formats.tiff.fieldtypes.FieldType;
 import org.apache.sanselan.util.Debug;
 
 public class TiffReader extends BinaryFileParser implements TiffConstants
@@ -188,6 +189,15 @@ public class TiffReader extends BinaryFi
                 // {
                 TiffField field = new TiffField(tag, dirType, type, length,
                         valueOffset, valueOffsetBytes, getByteOrder());
+                FieldType fieldType = TiffField.getFieldType(type);
+                if (!strict &&
+                    !fieldType.isLocalValue(field) &&
+                    (valueOffset < 0 || ((long)valueOffset) + ((long)field.getValueLengthInBytes())
> byteSource.getLength()))
+                {
+                    // corrupt field would throw, ignore it
+                    continue;
+                }
+
                 field.setSortHint(i);
 
                 // Debug.debug("tagInfo", field.tagInfo);



Mime
View raw message