Program: 154084
Project: 154084
Buggy source:
private void initialize(SeekableStream stream) throws IOException {
  long nextTagOffset;
  int i, j;
  IFDOffset=stream.getFilePointer();
  numEntries=readUnsignedShort(stream);
  fields=new TIFFField[numEntries];
  for (i=0; i < numEntries; i++) {
    int tag=readUnsignedShort(stream);
    int type=readUnsignedShort(stream);
    int count=(int)(readUnsignedInt(stream));
    int value=0;
    nextTagOffset=stream.getFilePointer() + 4;
    try {
      if (count * sizeOfType[type] > 4) {
        value=(int)(readUnsignedInt(stream));
        stream.seek(value);
      }
    }
 catch (    ArrayIndexOutOfBoundsException ae) {
      System.err.println(tag + "String_Node_Str" + JaiI18N.getString("String_Node_Str"));
      stream.seek(nextTagOffset);
      continue;
    }
    fieldIndex.put(new Integer(tag),new Integer(i));
    Object obj=null;
switch (type) {
case TIFFField.TIFF_BYTE:
case TIFFField.TIFF_SBYTE:
case TIFFField.TIFF_UNDEFINED:
case TIFFField.TIFF_ASCII:
      byte[] bvalues=new byte[count];
    stream.readFully(bvalues,0,count);
  if (type == TIFFField.TIFF_ASCII) {
    int index=0, prevIndex=0;
    Vector v=new Vector();
    while (index < count) {
      while ((index < count) && (bvalues[index++] != 0))       ;
      v.add(new String(bvalues,prevIndex,(index - prevIndex)));
      prevIndex=index;
    }
    count=v.size();
    String strings[]=new String[count];
    for (int c=0; c < count; c++) {
      strings[c]=(String)v.elementAt(c);
    }
    obj=strings;
  }
 else {
    obj=bvalues;
  }
break;
case TIFFField.TIFF_SHORT:
char[] cvalues=new char[count];
for (j=0; j < count; j++) {
cvalues[j]=(char)(readUnsignedShort(stream));
}
obj=cvalues;
break;
case TIFFField.TIFF_LONG:
long[] lvalues=new long[count];
for (j=0; j < count; j++) {
lvalues[j]=readUnsignedInt(stream);
}
obj=lvalues;
break;
case TIFFField.TIFF_RATIONAL:
long[][] llvalues=new long[count][2];
for (j=0; j < count; j++) {
llvalues[j][0]=readUnsignedInt(stream);
llvalues[j][1]=readUnsignedInt(stream);
}
obj=llvalues;
break;
case TIFFField.TIFF_SSHORT:
short[] svalues=new short[count];
for (j=0; j < count; j++) {
svalues[j]=readShort(stream);
}
obj=svalues;
break;
case TIFFField.TIFF_SLONG:
int[] ivalues=new int[count];
for (j=0; j < count; j++) {
ivalues[j]=readInt(stream);
}
obj=ivalues;
break;
case TIFFField.TIFF_SRATIONAL:
int[][] iivalues=new int[count][2];
for (j=0; j < count; j++) {
iivalues[j][0]=readInt(stream);
iivalues[j][1]=readInt(stream);
}
obj=iivalues;
break;
case TIFFField.TIFF_FLOAT:
float[] fvalues=new float[count];
for (j=0; j < count; j++) {
fvalues[j]=readFloat(stream);
}
obj=fvalues;
break;
case TIFFField.TIFF_DOUBLE:
double[] dvalues=new double[count];
for (j=0; j < count; j++) {
dvalues[j]=readDouble(stream);
}
obj=dvalues;
break;
default :
System.err.println(JaiI18N.getString("String_Node_Str"));
break;
}
fields[i]=new TIFFField(tag,type,count,obj);
stream.seek(nextTagOffset);
}
nextIFDOffset=readUnsignedInt(stream);
}

Fixed version (ground truth):
private void initialize(SeekableStream stream) throws IOException {
  long nextTagOffset;
  int i, j;
  IFDOffset=stream.getFilePointer();
  numEntries=readUnsignedShort(stream);
  fields=new TIFFField[numEntries];
  for (i=0; i < numEntries; i++) {
    int tag=readUnsignedShort(stream);
    int type=readUnsignedShort(stream);
    int count=(int)(readUnsignedInt(stream));
    int value=0;
    nextTagOffset=stream.getFilePointer() + 4;
    try {
      if (count * sizeOfType[type] > 4) {
        value=(int)(readUnsignedInt(stream));
        stream.seek(value);
      }
    }
 catch (    ArrayIndexOutOfBoundsException ae) {
      System.err.println(tag + "String_Node_Str" + JaiI18N.getString("String_Node_Str"));
      stream.seek(nextTagOffset);
      continue;
    }
    fieldIndex.put(new Integer(tag),new Integer(i));
    Object obj=null;
    try {
switch (type) {
case TIFFField.TIFF_BYTE:
case TIFFField.TIFF_SBYTE:
case TIFFField.TIFF_UNDEFINED:
case TIFFField.TIFF_ASCII:
        byte[] bvalues=new byte[count];
      stream.readFully(bvalues,0,count);
    if (type == TIFFField.TIFF_ASCII) {
      int index=0, prevIndex=0;
      Vector v=new Vector();
      while (index < count) {
        while ((index < count) && (bvalues[index++] != 0))         ;
        v.add(new String(bvalues,prevIndex,(index - prevIndex)));
        prevIndex=index;
      }
      count=v.size();
      String strings[]=new String[count];
      for (int c=0; c < count; c++) {
        strings[c]=(String)v.elementAt(c);
      }
      obj=strings;
    }
 else {
      obj=bvalues;
    }
  break;
case TIFFField.TIFF_SHORT:
char[] cvalues=new char[count];
for (j=0; j < count; j++) {
cvalues[j]=(char)(readUnsignedShort(stream));
}
obj=cvalues;
break;
case TIFFField.TIFF_LONG:
long[] lvalues=new long[count];
for (j=0; j < count; j++) {
lvalues[j]=readUnsignedInt(stream);
}
obj=lvalues;
break;
case TIFFField.TIFF_RATIONAL:
long[][] llvalues=new long[count][2];
for (j=0; j < count; j++) {
llvalues[j][0]=readUnsignedInt(stream);
llvalues[j][1]=readUnsignedInt(stream);
}
obj=llvalues;
break;
case TIFFField.TIFF_SSHORT:
short[] svalues=new short[count];
for (j=0; j < count; j++) {
svalues[j]=readShort(stream);
}
obj=svalues;
break;
case TIFFField.TIFF_SLONG:
int[] ivalues=new int[count];
for (j=0; j < count; j++) {
ivalues[j]=readInt(stream);
}
obj=ivalues;
break;
case TIFFField.TIFF_SRATIONAL:
int[][] iivalues=new int[count][2];
for (j=0; j < count; j++) {
iivalues[j][0]=readInt(stream);
iivalues[j][1]=readInt(stream);
}
obj=iivalues;
break;
case TIFFField.TIFF_FLOAT:
float[] fvalues=new float[count];
for (j=0; j < count; j++) {
fvalues[j]=readFloat(stream);
}
obj=fvalues;
break;
case TIFFField.TIFF_DOUBLE:
double[] dvalues=new double[count];
for (j=0; j < count; j++) {
dvalues[j]=readDouble(stream);
}
obj=dvalues;
break;
default :
System.err.println(JaiI18N.getString("String_Node_Str"));
break;
}
fields[i]=new TIFFField(tag,type,count,obj);
}
 catch (EOFException eofe) {
if (tag <= 532 || tag == 33432) {
throw eofe;
}
fieldIndex.remove(new Integer(tag));
}
stream.seek(nextTagOffset);
}
nextIFDOffset=readUnsignedInt(stream);
}