Changeset 5757 for branches/4.1


Ignore:
Timestamp:
12/22/09 09:46:12 (10 years ago)
Author:
melissa
Message:

Tweaks to allow TIFFs with missing IFD pointers to be read.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r5621 r5757  
    289289      int tag = in.readShort() & 0xffff; 
    290290      int type = in.readShort() & 0xffff; 
    291       // BigTIFF case is a slight hack 
     291      // BigTIFF case is a slight hack because the count could be 
     292      // greater than Integer.MAX_VALUE 
    292293      int count = bigTiff ? (int) (in.readLong() & 0xffffffff) : in.readInt(); 
     294      int bpe = IFD.getIFDTypeLength(type); 
    293295 
    294296      LogTools.debug("getIFDs: read " + IFD.getIFDTagName(tag) + 
    295297        " (type=" + IFD.getIFDTypeName(type) + "; count=" + count + ")"); 
    296       if (count < 0) return null; // invalid data 
     298      if (count < 0 || bpe <= 0) { 
     299        // invalid data 
     300        in.skipBytes(bytesPerEntry - 4 - (bigTiff ? 8 : 4)); 
     301        continue; 
     302      } 
    297303      Object value = null; 
    298  
    299       int bpe = IFD.getIFDTypeLength(type); 
    300       if (bpe <= 0) return null; // invalid data 
    301304 
    302305      if (count > threshhold / bpe) { 
     
    313316          " array elements for tag " + tag); 
    314317      } 
     318 
     319      if (count < 0 || count > in.length()) break; 
    315320 
    316321      if (type == IFD.BYTE) { 
     
    445450        } 
    446451      } 
    447       if (value != null) ifd.put(new Integer(tag), value); 
     452      if (value != null && !ifd.containsKey(new Integer(tag))) { 
     453        ifd.put(new Integer(tag), value); 
     454      } 
    448455    } 
    449456    in.seek(offset + baseOffset + bytesPerEntry * numEntries); 
     457 
     458    if (!(ifd.get(IFD.IMAGE_WIDTH) instanceof Number) || 
     459      !(ifd.get(IFD.IMAGE_LENGTH) instanceof Number)) 
     460    { 
     461      return null; 
     462    } 
    450463 
    451464    return ifd; 
Note: See TracChangeset for help on using the changeset viewer.