Program: 33348
Project: 33348
Buggy source:
@Override public void read() throws IOException {
  if (data != null) {
    RandomAccessInputStream exifIn=new FileCacheRandomAccessInputStream(new ByteArrayInputStream(data));
    TIFFTweaker.readIFDs(ifds,exifIn);
    if (ifds.size() >= 2) {
      containsThumbnail=true;
      IFD thumbnailIFD=ifds.get(1);
      int width=-1;
      int height=-1;
      TiffField<?> field=thumbnailIFD.getField(TiffTag.IMAGE_WIDTH);
      if (field != null)       width=field.getDataAsLong()[0];
      field=thumbnailIFD.getField(TiffTag.IMAGE_LENGTH);
      if (field != null)       height=field.getDataAsLong()[0];
      field=thumbnailIFD.getField(TiffTag.JPEG_INTERCHANGE_FORMAT);
      if (field != null) {
        int thumbnailOffset=field.getDataAsLong()[0];
        field=thumbnailIFD.getField(TiffTag.JPEG_INTERCHANGE_FORMAT_LENGTH);
        int thumbnailLen=field.getDataAsLong()[0];
        exifIn.seek(thumbnailOffset);
        byte[] thumbnailData=new byte[thumbnailLen];
        exifIn.readFully(thumbnailData);
        thumbnail=new ExifThumbnail(width,height,Thumbnail.DATA_TYPE_KJpegRGB,thumbnailData,thumbnailIFD);
      }
 else {
        field=thumbnailIFD.getField(TiffTag.STRIP_OFFSETS);
        if (field == null)         field=thumbnailIFD.getField(TiffTag.TILE_OFFSETS);
        if (field != null) {
          exifIn.seek(0);
          ByteArrayOutputStream bout=new ByteArrayOutputStream();
          RandomAccessOutputStream tiffout=new FileCacheRandomAccessOutputStream(bout);
          TIFFTweaker.retainPages(exifIn,tiffout,1);
          tiffout.close();
          thumbnail=new ExifThumbnail(width,height,Thumbnail.DATA_TYPE_TIFF,bout.toByteArray(),thumbnailIFD);
        }
      }
    }
    exifIn.close();
  }
  loaded=true;
}

Fixed version (ground truth):
@Override public void read() throws IOException {
  if (data != null) {
    RandomAccessInputStream exifIn=new FileCacheRandomAccessInputStream(new ByteArrayInputStream(data));
    TIFFTweaker.readIFDs(ifds,exifIn);
    if (ifds.size() >= 2) {
      IFD thumbnailIFD=ifds.get(1);
      int width=-1;
      int height=-1;
      TiffField<?> field=thumbnailIFD.getField(TiffTag.IMAGE_WIDTH);
      if (field != null)       width=field.getDataAsLong()[0];
      field=thumbnailIFD.getField(TiffTag.IMAGE_LENGTH);
      if (field != null)       height=field.getDataAsLong()[0];
      field=thumbnailIFD.getField(TiffTag.JPEG_INTERCHANGE_FORMAT);
      if (field != null) {
        int thumbnailOffset=field.getDataAsLong()[0];
        field=thumbnailIFD.getField(TiffTag.JPEG_INTERCHANGE_FORMAT_LENGTH);
        int thumbnailLen=field.getDataAsLong()[0];
        exifIn.seek(thumbnailOffset);
        byte[] thumbnailData=new byte[thumbnailLen];
        exifIn.readFully(thumbnailData);
        thumbnail=new ExifThumbnail(width,height,Thumbnail.DATA_TYPE_KJpegRGB,thumbnailData,thumbnailIFD);
        containsThumbnail=true;
      }
 else {
        field=thumbnailIFD.getField(TiffTag.STRIP_OFFSETS);
        if (field == null)         field=thumbnailIFD.getField(TiffTag.TILE_OFFSETS);
        if (field != null) {
          exifIn.seek(0);
          ByteArrayOutputStream bout=new ByteArrayOutputStream();
          RandomAccessOutputStream tiffout=new FileCacheRandomAccessOutputStream(bout);
          TIFFTweaker.retainPages(exifIn,tiffout,1);
          tiffout.close();
          thumbnail=new ExifThumbnail(width,height,Thumbnail.DATA_TYPE_TIFF,bout.toByteArray(),thumbnailIFD);
          containsThumbnail=true;
        }
      }
    }
    exifIn.close();
  }
  loaded=true;
}