Changeset 7484


Ignore:
Timestamp:
01/04/11 12:05:14 (9 years ago)
Author:
melissa
Message:

Various fixes to allow retrieval of pixel data from truncated TIFFs.

Files:
6 edited

Legend:

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

    r6064 r7484  
    713713      offsets = getIFDLongArray(STRIP_OFFSETS, false); 
    714714    } 
     715    if (offsets == null) return null; 
    715716 
    716717    if (isTiled()) return offsets; 
     
    748749      // have the StripByteCounts tag, it also won't have the RowsPerStrip tag 
    749750      long[] offsets = getStripOffsets(); 
     751      if (offsets == null) return null; 
    750752      int bytesPerSample = getBytesPerSample()[0]; 
    751753      long imageWidth = getImageWidth(); 
     
    851853      sb.append("="); 
    852854      Object value = get(tags[entry]); 
    853       if ((value instanceof Boolean) || (value instanceof Number) || 
     855      if (value == null) { 
     856        sb.append("null"); 
     857      } 
     858      else if ((value instanceof Boolean) || (value instanceof Number) || 
    854859        (value instanceof String)) 
    855860      { 
  • branches/4.1/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r6464 r7484  
    372372        LogTools.debug("getIFDs: truncated " + (oldCount - count) + 
    373373          " array elements for tag " + tag); 
     374        if (count < 0) count = oldCount; 
    374375      } 
    375376      if (count < 0 || count > in.length()) break; 
     
    420421    int count = entry.getValueCount(); 
    421422    long offset = entry.getValueOffset(); 
     423 
     424    if (offset >= in.length()) { 
     425      return null; 
     426    } 
    422427 
    423428    if (offset != in.getFilePointer()) { 
     
    702707      long[] stripByteCounts = ifd.getStripByteCounts(); 
    703708 
    704       int tile = (int) ((y / tileLength) * numTileCols + (x / tileWidth)); 
    705       in.seek(stripOffsets[tile]); 
    706       in.read(buf, 0, (int) Math.min(buf.length, stripByteCounts[tile])); 
     709      if (stripOffsets != null && stripByteCounts != null) { 
     710        int tile = (int) ((y / tileLength) * numTileCols + (x / tileWidth)); 
     711        in.seek(stripOffsets[tile]); 
     712        in.read(buf, 0, (int) Math.min(buf.length, stripByteCounts[tile])); 
     713      } 
    707714      return buf; 
    708715    } 
  • branches/4.2/components/bio-formats/src/loci/formats/tiff/IFD.java

    r7007 r7484  
    710710      offsets = getIFDLongArray(STRIP_OFFSETS); 
    711711    } 
     712    if (offsets == null) return null; 
    712713 
    713714    for (int i=0; i<offsets.length; i++) { 
     
    751752      // have the StripByteCounts tag, it also won't have the RowsPerStrip tag 
    752753      long[] offsets = getStripOffsets(); 
     754      if (offsets == null) return null; 
    753755      int bytesPerSample = getBytesPerSample()[0]; 
    754756      long imageWidth = getImageWidth(); 
     
    878880      Object value = get(tag); 
    879881      String v = null; 
    880       if ((value instanceof Boolean) || (value instanceof Number) || 
     882      if (value == null) { 
     883        LOGGER.trace("\t{}=null", getIFDTagName(tag.intValue())); 
     884      } 
     885      else if ((value instanceof Boolean) || (value instanceof Number) || 
    881886        (value instanceof String) || (value instanceof PhotoInterp) || 
    882887        (value instanceof TiffCompression) || (value instanceof TiffIFDEntry)) 
  • branches/4.2/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r7007 r7484  
    360360        LOGGER.trace("getIFDs: truncated {} array elements for tag {}", 
    361361          (oldCount - count), tag); 
     362        if (count < 0) count = oldCount; 
    362363      } 
    363364      if (count < 0 || count > in.length()) break; 
     
    400401    LOGGER.trace("Reading entry {} from {}; type={}, count={}", 
    401402      new Object[] {entry.getTag(), offset, type, count}); 
     403 
     404    if (offset >= in.length()) { 
     405      return null; 
     406    } 
    402407 
    403408    if (offset != in.getFilePointer()) { 
     
    660665      long[] stripByteCounts = ifd.getStripByteCounts(); 
    661666 
    662       int tile = (int) ((y / tileLength) * numTileCols + (x / tileWidth)); 
    663  
    664       if (stripByteCounts[tile] == numSamples && pixel > 1) { 
    665         stripByteCounts[tile] *= pixel; 
    666       } 
    667  
    668       in.seek(stripOffsets[tile]); 
    669       in.read(buf, 0, (int) Math.min(buf.length, stripByteCounts[tile])); 
     667      if (stripOffsets != null && stripByteCounts != null) { 
     668        int tile = (int) ((y / tileLength) * numTileCols + (x / tileWidth)); 
     669 
     670        if (stripByteCounts[tile] == numSamples && pixel > 1) { 
     671          stripByteCounts[tile] *= pixel; 
     672        } 
     673 
     674        in.seek(stripOffsets[tile]); 
     675        in.read(buf, 0, (int) Math.min(buf.length, stripByteCounts[tile])); 
     676      } 
    670677      return buf; 
    671678    } 
  • trunk/components/bio-formats/src/loci/formats/tiff/IFD.java

    r6881 r7484  
    710710      offsets = getIFDLongArray(STRIP_OFFSETS); 
    711711    } 
     712    if (offsets == null) return null; 
    712713 
    713714    for (int i=0; i<offsets.length; i++) { 
     
    751752      // have the StripByteCounts tag, it also won't have the RowsPerStrip tag 
    752753      long[] offsets = getStripOffsets(); 
     754      if (offsets == null) return null; 
    753755      int bytesPerSample = getBytesPerSample()[0]; 
    754756      long imageWidth = getImageWidth(); 
     
    878880      Object value = get(tag); 
    879881      String v = null; 
    880       if ((value instanceof Boolean) || (value instanceof Number) || 
     882      if (value == null) { 
     883        LOGGER.trace("\t{}=null", getIFDTagName(tag.intValue())); 
     884      } 
     885      else if ((value instanceof Boolean) || (value instanceof Number) || 
    881886        (value instanceof String) || (value instanceof PhotoInterp) || 
    882887        (value instanceof TiffCompression) || (value instanceof TiffIFDEntry)) 
  • trunk/components/bio-formats/src/loci/formats/tiff/TiffParser.java

    r7483 r7484  
    360360        LOGGER.trace("getIFDs: truncated {} array elements for tag {}", 
    361361          (oldCount - count), tag); 
     362        if (count < 0) count = oldCount; 
    362363      } 
    363364      if (count < 0 || count > in.length()) break; 
     
    400401    LOGGER.trace("Reading entry {} from {}; type={}, count={}", 
    401402      new Object[] {entry.getTag(), offset, type, count}); 
     403 
     404    if (offset >= in.length()) { 
     405      return null; 
     406    } 
    402407 
    403408    if (offset != in.getFilePointer()) { 
     
    662667      long[] stripByteCounts = ifd.getStripByteCounts(); 
    663668 
    664       int firstTile = (int) ((y / tileLength) * numTileCols + (x / tileWidth)); 
    665       int lastTile = 
    666         (int) (((y + height) / tileLength) * numTileCols + (x / tileWidth)); 
    667       lastTile = (int) Math.min(lastTile, stripOffsets.length - 1); 
    668  
    669       int offset = 0; 
    670       for (int tile=firstTile; tile<=lastTile; tile++) { 
    671         if (stripByteCounts[tile] == numSamples && pixel > 1) { 
    672           stripByteCounts[tile] *= pixel; 
     669      if (stripOffsets != null && stripByteCounts != null) { 
     670        long column = x / tileWidth; 
     671        int firstTile = (int) ((y / tileLength) * numTileCols + column); 
     672        int lastTile = 
     673          (int) (((y + height) / tileLength) * numTileCols + column); 
     674        lastTile = (int) Math.min(lastTile, stripOffsets.length - 1); 
     675 
     676        int offset = 0; 
     677        for (int tile=firstTile; tile<=lastTile; tile++) { 
     678          if (stripByteCounts[tile] == numSamples && pixel > 1) { 
     679            stripByteCounts[tile] *= pixel; 
     680          } 
     681 
     682          in.seek(stripOffsets[tile]); 
     683          int len = (int) Math.min(buf.length - offset, stripByteCounts[tile]); 
     684          in.read(buf, offset, len); 
     685          offset += len; 
    673686        } 
    674  
    675         in.seek(stripOffsets[tile]); 
    676         int len = (int) Math.min(buf.length - offset, stripByteCounts[tile]); 
    677         in.read(buf, offset, len); 
    678         offset += len; 
    679687      } 
    680688      return buf; 
Note: See TracChangeset for help on using the changeset viewer.