Program: 110347
Project: 110347
Buggy source:
/** 
 * Returns the stream info read from the available descriptors, or -1 if no descriptors are present. Sets   {@code data}'s position to the end of the descriptors.
 * @param data A buffer with its position set to the start of the first descriptor.
 * @param length The length of descriptors to read from the current position in {@code data}.
 * @return The stream info read from the available descriptors, or -1 if nodescriptors are present.
 */
private EsInfo readEsInfo(ParsableByteArray data,int length){
  int descriptorsEndPosition=data.getPosition() + length;
  int streamType=-1;
  int audioType=-1;
  String language=null;
  while (data.getPosition() < descriptorsEndPosition) {
    int descriptorTag=data.readUnsignedByte();
    int descriptorLength=data.readUnsignedByte();
    if (descriptorTag == TS_PMT_DESC_REGISTRATION) {
      long formatIdentifier=data.readUnsignedInt();
      if (formatIdentifier == AC3_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_AC3;
      }
 else       if (formatIdentifier == E_AC3_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_E_AC3;
      }
 else       if (formatIdentifier == HEVC_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_H265;
      }
      break;
    }
 else     if (descriptorTag == TS_PMT_DESC_AC3) {
      streamType=TS_STREAM_TYPE_AC3;
    }
 else     if (descriptorTag == TS_PMT_DESC_EAC3) {
      streamType=TS_STREAM_TYPE_E_AC3;
    }
 else     if (descriptorTag == TS_PMT_DESC_DTS) {
      streamType=TS_STREAM_TYPE_DTS;
    }
 else     if (descriptorTag == TS_PMT_DESC_ISO639_LANG) {
      language=new String(data.data,data.getPosition(),3).trim();
      audioType=data.data[data.getPosition() + 3];
    }
    data.skipBytes(descriptorLength);
  }
  data.setPosition(descriptorsEndPosition);
  return new EsInfo(streamType,audioType,language);
}

Fixed version (ground truth):
/** 
 * Returns the stream info read from the available descriptors, or -1 if no descriptors are present. Sets   {@code data}'s position to the end of the descriptors.
 * @param data A buffer with its position set to the start of the first descriptor.
 * @param length The length of descriptors to read from the current position in {@code data}.
 * @return The stream info read from the available descriptors, or -1 if nodescriptors are present.
 */
private EsInfo readEsInfo(ParsableByteArray data,int length){
  int descriptorsEndPosition=data.getPosition() + length;
  int streamType=-1;
  int audioType=-1;
  String language=null;
  while (data.getPosition() < descriptorsEndPosition) {
    int descriptorTag=data.readUnsignedByte();
    int descriptorLength=data.readUnsignedByte();
    int positionOfNextDescriptor=data.getPosition() + descriptorLength;
    if (descriptorTag == TS_PMT_DESC_REGISTRATION) {
      long formatIdentifier=data.readUnsignedInt();
      if (formatIdentifier == AC3_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_AC3;
      }
 else       if (formatIdentifier == E_AC3_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_E_AC3;
      }
 else       if (formatIdentifier == HEVC_FORMAT_IDENTIFIER) {
        streamType=TS_STREAM_TYPE_H265;
      }
    }
 else     if (descriptorTag == TS_PMT_DESC_AC3) {
      streamType=TS_STREAM_TYPE_AC3;
    }
 else     if (descriptorTag == TS_PMT_DESC_EAC3) {
      streamType=TS_STREAM_TYPE_E_AC3;
    }
 else     if (descriptorTag == TS_PMT_DESC_DTS) {
      streamType=TS_STREAM_TYPE_DTS;
    }
 else     if (descriptorTag == TS_PMT_DESC_ISO639_LANG) {
      language=new String(data.data,data.getPosition(),3).trim();
      audioType=data.data[data.getPosition() + 3];
    }
    data.skipBytes(positionOfNextDescriptor - data.getPosition());
  }
  data.setPosition(descriptorsEndPosition);
  return new EsInfo(streamType,audioType,language);
}