Program: 92896
Project: 92896
Buggy source:
/** 
 * Processes the provided JPEG data, and extracts the specified JPEG segments into a   {@link JpegSegmentData} object.<p/> Will not return SOS (start of scan) or EOI (end of image) segments.
 * @param reader a {@link SequentialReader} from which the JPEG data will be read. It must be positioned at thebeginning of the JPEG data stream.
 * @param segmentTypes the set of JPEG segments types that are to be returned. If this argument is <code>null</code>then all found segment types are returned.
 */
@NotNull public static JpegSegmentData readSegments(@NotNull final SequentialReader reader,@Nullable Iterable<JpegSegmentType> segmentTypes) throws JpegProcessingException, IOException {
  assert(reader.isMotorolaByteOrder());
  final int magicNumber=reader.getUInt16();
  if (magicNumber != 0xFFD8) {
    throw new JpegProcessingException("String_Node_Str" + Integer.toHexString(magicNumber));
  }
  Set<Byte> segmentTypeBytes=null;
  if (segmentTypes != null) {
    segmentTypeBytes=new HashSet<Byte>();
    for (    JpegSegmentType segmentType : segmentTypes) {
      segmentTypeBytes.add(segmentType.byteValue);
    }
  }
  JpegSegmentData segmentData=new JpegSegmentData();
  do {
    final short segmentIdentifier=reader.getUInt8();
    if (segmentIdentifier != 0xFF)     throw new JpegProcessingException("String_Node_Str" + Integer.toHexString(segmentIdentifier).toUpperCase());
    byte segmentType=reader.getInt8();
    while (segmentType == (byte)0xFF)     segmentType=reader.getInt8();
    if (segmentType == 0)     throw new JpegProcessingException("String_Node_Str");
    if (segmentType == SEGMENT_SOS) {
      return segmentData;
    }
    if (segmentType == MARKER_EOI) {
      return segmentData;
    }
    int segmentLength=reader.getUInt16();
    segmentLength-=2;
    if (segmentLength < 0)     throw new JpegProcessingException("String_Node_Str");
    if (segmentTypeBytes == null || segmentTypeBytes.contains(segmentType)) {
      byte[] segmentBytes=reader.getBytes(segmentLength);
      assert(segmentLength == segmentBytes.length);
      segmentData.addSegment(segmentType,segmentBytes);
    }
 else {
      if (!reader.trySkip(segmentLength)) {
        return segmentData;
      }
    }
  }
 while (true);
}

Fixed version (ground truth):
/** 
 * Processes the provided JPEG data, and extracts the specified JPEG segments into a   {@link JpegSegmentData} object.<p> Will not return SOS (start of scan) or EOI (end of image) segments.
 * @param reader a {@link SequentialReader} from which the JPEG data will be read. It must be positioned at thebeginning of the JPEG data stream.
 * @param segmentTypes the set of JPEG segments types that are to be returned. If this argument is <code>null</code>then all found segment types are returned.
 */
@NotNull public static JpegSegmentData readSegments(@NotNull final SequentialReader reader,@Nullable Iterable<JpegSegmentType> segmentTypes) throws JpegProcessingException, IOException {
  assert(reader.isMotorolaByteOrder());
  final int magicNumber=reader.getUInt16();
  if (magicNumber != 0xFFD8) {
    throw new JpegProcessingException("String_Node_Str" + Integer.toHexString(magicNumber));
  }
  Set<Byte> segmentTypeBytes=null;
  if (segmentTypes != null) {
    segmentTypeBytes=new HashSet<Byte>();
    for (    JpegSegmentType segmentType : segmentTypes) {
      segmentTypeBytes.add(segmentType.byteValue);
    }
  }
  JpegSegmentData segmentData=new JpegSegmentData();
  do {
    final short segmentIdentifier=reader.getUInt8();
    if (segmentIdentifier != 0xFF)     throw new JpegProcessingException("String_Node_Str" + Integer.toHexString(segmentIdentifier).toUpperCase());
    byte segmentType=reader.getInt8();
    while (segmentType == (byte)0xFF)     segmentType=reader.getInt8();
    if (segmentType == 0)     throw new JpegProcessingException("String_Node_Str");
    if (segmentType == SEGMENT_SOS) {
      return segmentData;
    }
    if (segmentType == MARKER_EOI) {
      return segmentData;
    }
    int segmentLength=reader.getUInt16();
    segmentLength-=2;
    if (segmentLength < 0)     throw new JpegProcessingException("String_Node_Str");
    if (segmentTypeBytes == null || segmentTypeBytes.contains(segmentType)) {
      byte[] segmentBytes=reader.getBytes(segmentLength);
      assert(segmentLength == segmentBytes.length);
      segmentData.addSegment(segmentType,segmentBytes);
    }
 else {
      if (!reader.trySkip(segmentLength)) {
        return segmentData;
      }
    }
  }
 while (true);
}