Program: 92886
Project: 92886
Buggy source:
private static void processChunk(@NotNull Metadata metadata,@NotNull PngChunk chunk) throws PngProcessingException, IOException {
  PngChunkType chunkType=chunk.getType();
  byte[] bytes=chunk.getBytes();
  if (chunkType.equals(PngChunkType.IHDR)) {
    PngHeader header=new PngHeader(bytes);
    PngDirectory directory=new PngDirectory(PngChunkType.IHDR);
    directory.setInt(PngDirectory.TAG_IMAGE_WIDTH,header.getImageWidth());
    directory.setInt(PngDirectory.TAG_IMAGE_HEIGHT,header.getImageHeight());
    directory.setInt(PngDirectory.TAG_BITS_PER_SAMPLE,header.getBitsPerSample());
    directory.setInt(PngDirectory.TAG_COLOR_TYPE,header.getColorType().getNumericValue());
    directory.setInt(PngDirectory.TAG_COMPRESSION_TYPE,header.getCompressionType());
    directory.setInt(PngDirectory.TAG_FILTER_METHOD,header.getFilterMethod());
    directory.setInt(PngDirectory.TAG_INTERLACE_METHOD,header.getInterlaceMethod());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.PLTE)) {
    PngDirectory directory=new PngDirectory(PngChunkType.PLTE);
    directory.setInt(PngDirectory.TAG_PALETTE_SIZE,bytes.length / 3);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.tRNS)) {
    PngDirectory directory=new PngDirectory(PngChunkType.tRNS);
    directory.setInt(PngDirectory.TAG_PALETTE_HAS_TRANSPARENCY,1);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.sRGB)) {
    int srgbRenderingIntent=new SequentialByteArrayReader(bytes).getInt8();
    PngDirectory directory=new PngDirectory(PngChunkType.sRGB);
    directory.setInt(PngDirectory.TAG_SRGB_RENDERING_INTENT,srgbRenderingIntent);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.cHRM)) {
    PngChromaticities chromaticities=new PngChromaticities(bytes);
    PngChromaticitiesDirectory directory=new PngChromaticitiesDirectory();
    directory.setInt(PngChromaticitiesDirectory.TAG_WHITE_POINT_X,chromaticities.getWhitePointX());
    directory.setInt(PngChromaticitiesDirectory.TAG_WHITE_POINT_X,chromaticities.getWhitePointX());
    directory.setInt(PngChromaticitiesDirectory.TAG_RED_X,chromaticities.getRedX());
    directory.setInt(PngChromaticitiesDirectory.TAG_RED_Y,chromaticities.getRedY());
    directory.setInt(PngChromaticitiesDirectory.TAG_GREEN_X,chromaticities.getGreenX());
    directory.setInt(PngChromaticitiesDirectory.TAG_GREEN_Y,chromaticities.getGreenY());
    directory.setInt(PngChromaticitiesDirectory.TAG_BLUE_X,chromaticities.getBlueX());
    directory.setInt(PngChromaticitiesDirectory.TAG_BLUE_Y,chromaticities.getBlueY());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.gAMA)) {
    int gammaInt=new SequentialByteArrayReader(bytes).getInt32();
    PngDirectory directory=new PngDirectory(PngChunkType.gAMA);
    directory.setDouble(PngDirectory.TAG_GAMMA,gammaInt / 100000.0);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.iCCP)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String profileName=reader.getNullTerminatedString(79);
    PngDirectory directory=new PngDirectory(PngChunkType.iCCP);
    directory.setString(PngDirectory.TAG_ICC_PROFILE_NAME,profileName);
    byte compressionMethod=reader.getInt8();
    if (compressionMethod == 0) {
      int bytesLeft=bytes.length - profileName.length() - 2;
      byte[] compressedProfile=reader.getBytes(bytesLeft);
      InflaterInputStream inflateStream=new InflaterInputStream(new ByteArrayInputStream(compressedProfile));
      new IccReader().extract(new RandomAccessStreamReader(inflateStream),metadata);
      inflateStream.close();
    }
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.bKGD)) {
    PngDirectory directory=new PngDirectory(PngChunkType.bKGD);
    directory.setByteArray(PngDirectory.TAG_BACKGROUND_COLOR,bytes);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.tEXt)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String keyword=reader.getNullTerminatedString(79);
    int bytesLeft=bytes.length - keyword.length() - 1;
    String value=reader.getNullTerminatedString(bytesLeft);
    List<KeyValuePair> textPairs=new ArrayList<KeyValuePair>();
    textPairs.add(new KeyValuePair(keyword,value));
    PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
    directory.setObject(PngDirectory.TAG_TEXTUAL_DATA,textPairs);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.iTXt)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String keyword=reader.getNullTerminatedString(79);
    byte compressionFlag=reader.getInt8();
    byte compressionMethod=reader.getInt8();
    String languageTag=reader.getNullTerminatedString(bytes.length);
    String translatedKeyword=reader.getNullTerminatedString(bytes.length);
    int bytesLeft=bytes.length - keyword.length() - 1- 1- 1- languageTag.length()- 1- translatedKeyword.length()- 1;
    String text=null;
    if (compressionFlag == 0) {
      text=reader.getNullTerminatedString(bytesLeft);
    }
 else     if (compressionFlag == 1) {
      if (compressionMethod == 0) {
        text=StringUtil.fromStream(new InflaterInputStream(new ByteArrayInputStream(bytes,bytes.length - bytesLeft,bytesLeft)));
      }
 else {
        PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
        directory.addError("String_Node_Str");
        metadata.addDirectory(directory);
      }
    }
 else {
      PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
      directory.addError("String_Node_Str");
      metadata.addDirectory(directory);
    }
    if (text != null) {
      if (keyword.equals("String_Node_Str")) {
        new XmpReader().extract(text,metadata);
      }
 else {
        List<KeyValuePair> textPairs=new ArrayList<KeyValuePair>();
        textPairs.add(new KeyValuePair(keyword,text));
        PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
        directory.setObject(PngDirectory.TAG_TEXTUAL_DATA,textPairs);
        metadata.addDirectory(directory);
      }
    }
  }
 else   if (chunkType.equals(PngChunkType.tIME)) {
    SequentialByteArrayReader reader=new SequentialByteArrayReader(bytes);
    int year=reader.getUInt16();
    int month=reader.getUInt8() - 1;
    int day=reader.getUInt8();
    int hour=reader.getUInt8();
    int minute=reader.getUInt8();
    int second=reader.getUInt8();
    Calendar calendar=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
    calendar.set(year,month,day,hour,minute,second);
    PngDirectory directory=new PngDirectory(PngChunkType.tIME);
    directory.setDate(PngDirectory.TAG_LAST_MODIFICATION_TIME,calendar.getTime());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.pHYs)) {
    SequentialByteArrayReader reader=new SequentialByteArrayReader(bytes);
    int pixelsPerUnitX=reader.getInt32();
    int pixelsPerUnitY=reader.getInt32();
    byte unitSpecifier=reader.getInt8();
    PngDirectory directory=new PngDirectory(PngChunkType.pHYs);
    directory.setInt(PngDirectory.TAG_PIXELS_PER_UNIT_X,pixelsPerUnitX);
    directory.setInt(PngDirectory.TAG_PIXELS_PER_UNIT_Y,pixelsPerUnitY);
    directory.setInt(PngDirectory.TAG_UNIT_SPECIFIER,unitSpecifier);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.sBIT)) {
    PngDirectory directory=new PngDirectory(PngChunkType.sBIT);
    directory.setByteArray(PngDirectory.TAG_SIGNIFICANT_BITS,bytes);
    metadata.addDirectory(directory);
  }
}

Fixed version (ground truth):
private static void processChunk(@NotNull Metadata metadata,@NotNull PngChunk chunk) throws PngProcessingException, IOException {
  PngChunkType chunkType=chunk.getType();
  byte[] bytes=chunk.getBytes();
  if (chunkType.equals(PngChunkType.IHDR)) {
    PngHeader header=new PngHeader(bytes);
    PngDirectory directory=new PngDirectory(PngChunkType.IHDR);
    directory.setInt(PngDirectory.TAG_IMAGE_WIDTH,header.getImageWidth());
    directory.setInt(PngDirectory.TAG_IMAGE_HEIGHT,header.getImageHeight());
    directory.setInt(PngDirectory.TAG_BITS_PER_SAMPLE,header.getBitsPerSample());
    directory.setInt(PngDirectory.TAG_COLOR_TYPE,header.getColorType().getNumericValue());
    directory.setInt(PngDirectory.TAG_COMPRESSION_TYPE,header.getCompressionType());
    directory.setInt(PngDirectory.TAG_FILTER_METHOD,header.getFilterMethod());
    directory.setInt(PngDirectory.TAG_INTERLACE_METHOD,header.getInterlaceMethod());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.PLTE)) {
    PngDirectory directory=new PngDirectory(PngChunkType.PLTE);
    directory.setInt(PngDirectory.TAG_PALETTE_SIZE,bytes.length / 3);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.tRNS)) {
    PngDirectory directory=new PngDirectory(PngChunkType.tRNS);
    directory.setInt(PngDirectory.TAG_PALETTE_HAS_TRANSPARENCY,1);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.sRGB)) {
    int srgbRenderingIntent=new SequentialByteArrayReader(bytes).getInt8();
    PngDirectory directory=new PngDirectory(PngChunkType.sRGB);
    directory.setInt(PngDirectory.TAG_SRGB_RENDERING_INTENT,srgbRenderingIntent);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.cHRM)) {
    PngChromaticities chromaticities=new PngChromaticities(bytes);
    PngChromaticitiesDirectory directory=new PngChromaticitiesDirectory();
    directory.setInt(PngChromaticitiesDirectory.TAG_WHITE_POINT_X,chromaticities.getWhitePointX());
    directory.setInt(PngChromaticitiesDirectory.TAG_WHITE_POINT_Y,chromaticities.getWhitePointY());
    directory.setInt(PngChromaticitiesDirectory.TAG_RED_X,chromaticities.getRedX());
    directory.setInt(PngChromaticitiesDirectory.TAG_RED_Y,chromaticities.getRedY());
    directory.setInt(PngChromaticitiesDirectory.TAG_GREEN_X,chromaticities.getGreenX());
    directory.setInt(PngChromaticitiesDirectory.TAG_GREEN_Y,chromaticities.getGreenY());
    directory.setInt(PngChromaticitiesDirectory.TAG_BLUE_X,chromaticities.getBlueX());
    directory.setInt(PngChromaticitiesDirectory.TAG_BLUE_Y,chromaticities.getBlueY());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.gAMA)) {
    int gammaInt=new SequentialByteArrayReader(bytes).getInt32();
    PngDirectory directory=new PngDirectory(PngChunkType.gAMA);
    directory.setDouble(PngDirectory.TAG_GAMMA,gammaInt / 100000.0);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.iCCP)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String profileName=reader.getNullTerminatedString(79);
    PngDirectory directory=new PngDirectory(PngChunkType.iCCP);
    directory.setString(PngDirectory.TAG_ICC_PROFILE_NAME,profileName);
    byte compressionMethod=reader.getInt8();
    if (compressionMethod == 0) {
      int bytesLeft=bytes.length - profileName.length() - 2;
      byte[] compressedProfile=reader.getBytes(bytesLeft);
      InflaterInputStream inflateStream=new InflaterInputStream(new ByteArrayInputStream(compressedProfile));
      new IccReader().extract(new RandomAccessStreamReader(inflateStream),metadata);
      inflateStream.close();
    }
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.bKGD)) {
    PngDirectory directory=new PngDirectory(PngChunkType.bKGD);
    directory.setByteArray(PngDirectory.TAG_BACKGROUND_COLOR,bytes);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.tEXt)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String keyword=reader.getNullTerminatedString(79);
    int bytesLeft=bytes.length - keyword.length() - 1;
    String value=reader.getNullTerminatedString(bytesLeft);
    List<KeyValuePair> textPairs=new ArrayList<KeyValuePair>();
    textPairs.add(new KeyValuePair(keyword,value));
    PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
    directory.setObject(PngDirectory.TAG_TEXTUAL_DATA,textPairs);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.iTXt)) {
    SequentialReader reader=new SequentialByteArrayReader(bytes);
    String keyword=reader.getNullTerminatedString(79);
    byte compressionFlag=reader.getInt8();
    byte compressionMethod=reader.getInt8();
    String languageTag=reader.getNullTerminatedString(bytes.length);
    String translatedKeyword=reader.getNullTerminatedString(bytes.length);
    int bytesLeft=bytes.length - keyword.length() - 1- 1- 1- languageTag.length()- 1- translatedKeyword.length()- 1;
    String text=null;
    if (compressionFlag == 0) {
      text=reader.getNullTerminatedString(bytesLeft);
    }
 else     if (compressionFlag == 1) {
      if (compressionMethod == 0) {
        text=StringUtil.fromStream(new InflaterInputStream(new ByteArrayInputStream(bytes,bytes.length - bytesLeft,bytesLeft)));
      }
 else {
        PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
        directory.addError("String_Node_Str");
        metadata.addDirectory(directory);
      }
    }
 else {
      PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
      directory.addError("String_Node_Str");
      metadata.addDirectory(directory);
    }
    if (text != null) {
      if (keyword.equals("String_Node_Str")) {
        new XmpReader().extract(text,metadata);
      }
 else {
        List<KeyValuePair> textPairs=new ArrayList<KeyValuePair>();
        textPairs.add(new KeyValuePair(keyword,text));
        PngDirectory directory=new PngDirectory(PngChunkType.iTXt);
        directory.setObject(PngDirectory.TAG_TEXTUAL_DATA,textPairs);
        metadata.addDirectory(directory);
      }
    }
  }
 else   if (chunkType.equals(PngChunkType.tIME)) {
    SequentialByteArrayReader reader=new SequentialByteArrayReader(bytes);
    int year=reader.getUInt16();
    int month=reader.getUInt8() - 1;
    int day=reader.getUInt8();
    int hour=reader.getUInt8();
    int minute=reader.getUInt8();
    int second=reader.getUInt8();
    Calendar calendar=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
    calendar.set(year,month,day,hour,minute,second);
    PngDirectory directory=new PngDirectory(PngChunkType.tIME);
    directory.setDate(PngDirectory.TAG_LAST_MODIFICATION_TIME,calendar.getTime());
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.pHYs)) {
    SequentialByteArrayReader reader=new SequentialByteArrayReader(bytes);
    int pixelsPerUnitX=reader.getInt32();
    int pixelsPerUnitY=reader.getInt32();
    byte unitSpecifier=reader.getInt8();
    PngDirectory directory=new PngDirectory(PngChunkType.pHYs);
    directory.setInt(PngDirectory.TAG_PIXELS_PER_UNIT_X,pixelsPerUnitX);
    directory.setInt(PngDirectory.TAG_PIXELS_PER_UNIT_Y,pixelsPerUnitY);
    directory.setInt(PngDirectory.TAG_UNIT_SPECIFIER,unitSpecifier);
    metadata.addDirectory(directory);
  }
 else   if (chunkType.equals(PngChunkType.sBIT)) {
    PngDirectory directory=new PngDirectory(PngChunkType.sBIT);
    directory.setByteArray(PngDirectory.TAG_SIGNIFICANT_BITS,bytes);
    metadata.addDirectory(directory);
  }
}