commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1211312 - in /commons/proper/sanselan/trunk/src: main/java/org/apache/sanselan/formats/tiff/ test/data/images/tiff/2/
Date Wed, 07 Dec 2011 07:24:03 GMT
Author: damjan
Date: Wed Dec  7 07:24:02 2011
New Revision: 1211312

URL: http://svn.apache.org/viewvc?rev=1211312&view=rev
Log:
Fix another large offset bug in TIFF parsing,
fix the required fields necessary for bilevel images,
and add a test image for these changes and
the last few parsing changes.


Added:
    commons/proper/sanselan/trunk/src/test/data/images/tiff/2/
    commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.asm
    commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.tiff   (with
props)
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/TiffImageParser.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=1211312&r1=1211311&r2=1211312&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
Wed Dec  7 07:24:02 2011
@@ -280,6 +280,7 @@ public class TiffField implements TiffCo
             return;
 
         int valueLength = getValueLengthInBytes();
+        long valueLengthLong = 0xffffffffL & valueLength;
 
         // Debug.debug("fillInValue tag", tag);
         // Debug.debug("fillInValue tagInfo", tagInfo);
@@ -287,7 +288,7 @@ public class TiffField implements TiffCo
         // Debug.debug("fillInValue valueLength", valueLength);
 
         if (valueOffset < 0 ||
-            ((long)valueOffset) + ((long)valueLength) > byteSource.getLength()) {
+            ((long)valueOffset) + valueLengthLong > byteSource.getLength()) {
             throw new TiffValueOutsideFileBoundsException(
                 "Attempt to read byte range starting from " + valueOffset + " " +
                 "of length " + valueLength + " " +

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java?rev=1211312&r1=1211311&r2=1211312&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java
Wed Dec  7 07:24:02 2011
@@ -224,7 +224,7 @@ public class TiffImageParser extends Ima
         TiffField bitsPerSampleField = directory
                 .findField(TIFF_TAG_BITS_PER_SAMPLE);
 
-        int bitsPerSample = -1;
+        int bitsPerSample = 1;
         if ((bitsPerSampleField != null)
                 && (bitsPerSampleField.getValue() != null))
             bitsPerSample = bitsPerSampleField.getIntValueOrArraySum();
@@ -460,13 +460,18 @@ public class TiffImageParser extends Ima
                 .getIntValue();
         int height = directory.findField(TIFF_TAG_IMAGE_LENGTH, true)
                 .getIntValue();
-        int samplesPerPixel = directory.findField(TIFF_TAG_SAMPLES_PER_PIXEL,
-                true).getIntValue();
-        int bitsPerSample[] = directory.findField(TIFF_TAG_BITS_PER_SAMPLE,
-                true).getIntArrayValue();
-        // TODO: why are we using bits per sample twice? because one is a sum.
-        int bitsPerPixel = directory.findField(TIFF_TAG_BITS_PER_SAMPLE, true)
-                .getIntValueOrArraySum();
+        int samplesPerPixel = 1;
+        TiffField samplesPerPixelField = directory.findField(TIFF_TAG_SAMPLES_PER_PIXEL);
+        if (samplesPerPixelField != null)
+            samplesPerPixel = samplesPerPixelField.getIntValue();
+        int bitsPerSample[] = { 1 };
+        int bitsPerPixel = samplesPerPixel;
+        TiffField bitsPerSampleField = directory.findField(TIFF_TAG_BITS_PER_SAMPLE);
+        if (bitsPerSampleField != null)
+        {
+            bitsPerSample = bitsPerSampleField.getIntArrayValue();
+            bitsPerPixel = bitsPerSampleField.getIntValueOrArraySum();
+        }
 
         // int bitsPerPixel = getTagAsValueOrArraySum(entries,
         // TIFF_TAG_BITS_PER_SAMPLE);

Added: commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.asm
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.asm?rev=1211312&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.asm (added)
+++ commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.asm Wed
Dec  7 07:24:02 2011
@@ -0,0 +1,87 @@
+; Assemblers are the perfect tool for generating
+; custom test images as they let us insert offsets
+; to unknown locations easily and totally
+; customize the file byte-by-byte.
+;
+; To generate a TIFF from this, run:
+; nasm -f bin /path/to/this/file.asm -o /path/to/file.tiff
+
+; TIFF header
+db 0x49,0x49
+db 0x2a, 0x00
+db 0x08, 0x00, 0x00, 0x00
+
+; Number of directory entries
+dw 10
+
+; entry 0: tag, type, count, value
+dw 0x0100 ; tag = image width
+dw 3 ; type = short
+dd 1 ; length = 1
+dd 2 ; value = 2
+
+; entry 1
+dw 0x0101 ; tag = image length
+dw 3 ; type = short
+dd 1 ; length = 1
+dd 2 ; value = 2
+
+; entry 2
+dw 0x0103 ; tag = compression
+dw 3
+dd 1
+dd 1 ; no compression, but pack bits tightly
+
+; entry 3
+dw 0x0106 ; tag = PhotometricInterpretation
+dw 3
+dd 1
+dd 1 ; black is zero
+
+; entry 4
+dw 0x0111 ; tag = StripOffsets
+dw 4 ; type = long
+dd 1
+dd $imageStrip1
+
+; entry 5
+dw 0x0117 ; tag = StripByteCounts
+dw 4 ; type = long
+dd 1
+dd 2
+
+; entry 6
+dw 0x0116 ; tag = RowsPerStrip
+dw 4 ; type = long
+dd 1
+dd 2
+
+; entry 7
+dw 0x0110 ; tag = Model
+dw 2 ; type = ASCII
+dd 10
+dd 0x1fffffff ; outside file's bounds
+
+; entry 8
+dw 0x010f ; tag = Make
+dw 2 ; type = ASCII
+dd 50000 ; count - ridiculously high
+dd 0
+
+; entry 9
+dw 0x0132 ; tag = DateTime
+dw 2 ; type = ASCII
+dd 0xffffffce ; a huge, invalid length
+dd $dateTimeValue
+
+; offset to next directory - corrupt
+dd 0xffffffce ; -50
+
+; values that couldn't fit:
+dateTimeValue:
+dw '2011-12-07 00:00:00'
+
+; image data
+imageStrip1:
+db 0x80, 0x40
+

Added: commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.tiff
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.tiff?rev=1211312&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/sanselan/trunk/src/test/data/images/tiff/2/bad-offsets-lengths.tiff
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message