Changeset 7484 for trunk


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.

Location:
trunk/components/bio-formats/src/loci/formats/tiff
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.