Program: 107497
Project: 107497
Buggy source:
/** 
 * @return the packets represented in the FCI portion of an RTCPtransport-cc feedback packet. Warning: the timestamps are represented in the 250µs format used by the on-the-wire format, and don't represent local time. This is different than the timestamps expected as input when constructing a packet with {@link RTCPTCCPacket#RTCPTCCPacket(long,long,PacketMap,byte,DiagnosticContext)}.
 * @param fciBuffer the buffer which contains the FCI portion of the RTCPfeedback packet.
 * @param includeNotReceived whether the returned map should include thepackets described in the feedback packet as lost. Note that the RLE encoding allows ~2^16 packets to be described as lost in just a few bytes, so when parsing packets coming over the network it is wise to not blindly set this option to  {@code true}.
 */
static PacketMap getPacketsFromFci(ByteArrayBuffer fciBuffer,boolean includeNotReceived){
  int fciLen=-1;
  if (fciBuffer == null || (fciLen=fciBuffer.getLength()) < MIN_FCI_LENGTH) {
    logger.warn(PARSE_ERROR + "String_Node_Str" + fciLen);
    return null;
  }
  byte[] fciBuf=fciBuffer.getBuffer();
  int fciOff=fciBuffer.getOffset();
  int currentSeq=RTPUtils.readUint16AsInt(fciBuf,fciOff);
  int packetStatusCount=RTPUtils.readUint16AsInt(fciBuf,fciOff + 2);
  long referenceTime=getReferenceTime250us(fciBuffer);
  int currentPscOff=fciOff + PACKET_STATUS_CHUNK_OFFSET;
  int packetsRemaining=packetStatusCount;
  while (packetsRemaining > 0) {
    if (currentPscOff + CHUNK_SIZE_BYTES > fciOff + fciLen) {
      logger.warn(PARSE_ERROR + "String_Node_Str");
      return null;
    }
    int packetsInChunk=getPacketCount(fciBuf,currentPscOff);
    packetsRemaining-=packetsInChunk;
    currentPscOff+=CHUNK_SIZE_BYTES;
  }
  int deltaOff=currentPscOff;
  int currentDeltaOff=currentPscOff;
  currentPscOff=fciOff + PACKET_STATUS_CHUNK_OFFSET;
  packetsRemaining=packetStatusCount;
  PacketMap packets=new PacketMap();
  while (packetsRemaining > 0 && currentPscOff < deltaOff) {
    int packetsInChunk=Math.min(getPacketCount(fciBuf,currentPscOff),packetsRemaining);
    int chunkType=getChunkType(fciBuf,currentPscOff);
    if (packetsInChunk > 0 && chunkType == CHUNK_TYPE_RLE && readSymbol(fciBuf,currentPscOff,chunkType,0) == SYMBOL_NOT_RECEIVED) {
      if (includeNotReceived) {
        for (int i=0; i < packetsInChunk; i++) {
          int seq=(currentSeq + 1) % 0xffff;
          logPacket(seq,NEGATIVE_ONE,-1,SYMBOL_NOT_RECEIVED);
          packets.put(seq,NEGATIVE_ONE);
        }
      }
      currentSeq=(currentSeq + packetsInChunk) % 0xffff;
    }
 else {
      for (int i=0; i < packetsInChunk; i++) {
        int symbol=readSymbol(fciBuf,currentPscOff,chunkType,i);
        int delta=-1;
switch (symbol) {
case SYMBOL_SMALL_DELTA:
          if (currentDeltaOff >= fciOff + fciLen) {
            logger.warn(PARSE_ERROR + "String_Node_Str");
            return null;
          }
        delta=fciBuf[currentDeltaOff++] & 0xff;
      break;
case SYMBOL_LARGE_DELTA:
    if (currentDeltaOff + 1 >= fciOff + fciLen) {
      logger.warn(PARSE_ERROR + "String_Node_Str" + "String_Node_Str");
      return null;
    }
  delta=RTPUtils.readInt16AsInt(fciBuf,currentDeltaOff);
currentDeltaOff+=2;
break;
case SYMBOL_NOT_RECEIVED:
delta=-1;
break;
default :
logger.warn(PARSE_ERROR + "String_Node_Str" + symbol);
return null;
}
if (delta == -1) {
if (includeNotReceived) {
logPacket(currentSeq,NEGATIVE_ONE,delta,symbol);
packets.put(currentSeq,NEGATIVE_ONE);
}
}
 else {
referenceTime+=delta;
logPacket(currentSeq,referenceTime,delta,symbol);
packets.put(currentSeq,referenceTime);
}
currentSeq=(currentSeq + 1) & 0xffff;
}
}
currentPscOff+=CHUNK_SIZE_BYTES;
packetsRemaining-=packetsInChunk;
}
if (packetsRemaining > 0) {
logger.warn("String_Node_Str" + "String_Node_Str");
}
return packets;
}

Fixed version (ground truth):
/** 
 * @return the packets represented in the FCI portion of an RTCPtransport-cc feedback packet. Warning: the timestamps are represented in the 250µs format used by the on-the-wire format, and don't represent local time. This is different than the timestamps expected as input when constructing a packet with {@link RTCPTCCPacket#RTCPTCCPacket(long,long,PacketMap,byte,DiagnosticContext)}.
 * @param fciBuffer the buffer which contains the FCI portion of the RTCPfeedback packet.
 * @param includeNotReceived whether the returned map should include thepackets described in the feedback packet as lost. Note that the RLE encoding allows ~2^16 packets to be described as lost in just a few bytes, so when parsing packets coming over the network it is wise to not blindly set this option to  {@code true}.
 */
static PacketMap getPacketsFromFci(ByteArrayBuffer fciBuffer,boolean includeNotReceived){
  int fciLen=-1;
  if (fciBuffer == null || (fciLen=fciBuffer.getLength()) < MIN_FCI_LENGTH) {
    logger.warn(PARSE_ERROR + "String_Node_Str" + fciLen);
    return null;
  }
  byte[] fciBuf=fciBuffer.getBuffer();
  int fciOff=fciBuffer.getOffset();
  int currentSeq=RTPUtils.readUint16AsInt(fciBuf,fciOff);
  int packetStatusCount=RTPUtils.readUint16AsInt(fciBuf,fciOff + 2);
  long referenceTime=getReferenceTime250us(fciBuffer);
  int currentPscOff=fciOff + PACKET_STATUS_CHUNK_OFFSET;
  int packetsRemaining=packetStatusCount;
  while (packetsRemaining > 0) {
    if (currentPscOff + CHUNK_SIZE_BYTES > fciOff + fciLen) {
      logger.warn(PARSE_ERROR + "String_Node_Str");
      return null;
    }
    int packetsInChunk=getPacketCount(fciBuf,currentPscOff);
    packetsRemaining-=packetsInChunk;
    currentPscOff+=CHUNK_SIZE_BYTES;
  }
  int deltaOff=currentPscOff;
  int currentDeltaOff=currentPscOff;
  currentPscOff=fciOff + PACKET_STATUS_CHUNK_OFFSET;
  packetsRemaining=packetStatusCount;
  PacketMap packets=new PacketMap();
  while (packetsRemaining > 0 && currentPscOff < deltaOff) {
    int packetsInChunk=Math.min(getPacketCount(fciBuf,currentPscOff),packetsRemaining);
    int chunkType=getChunkType(fciBuf,currentPscOff);
    if (packetsInChunk > 0 && chunkType == CHUNK_TYPE_RLE && readSymbol(fciBuf,currentPscOff,chunkType,0) == SYMBOL_NOT_RECEIVED) {
      if (includeNotReceived) {
        for (int i=0; i < packetsInChunk; i++) {
          int seq=(currentSeq + i) % 0xffff;
          logPacket(seq,NEGATIVE_ONE,-1,SYMBOL_NOT_RECEIVED);
          packets.put(seq,NEGATIVE_ONE);
        }
      }
      currentSeq=(currentSeq + packetsInChunk) % 0xffff;
    }
 else {
      for (int i=0; i < packetsInChunk; i++) {
        int symbol=readSymbol(fciBuf,currentPscOff,chunkType,i);
        int delta=-1;
switch (symbol) {
case SYMBOL_SMALL_DELTA:
          if (currentDeltaOff >= fciOff + fciLen) {
            logger.warn(PARSE_ERROR + "String_Node_Str");
            return null;
          }
        delta=fciBuf[currentDeltaOff++] & 0xff;
      break;
case SYMBOL_LARGE_DELTA:
    if (currentDeltaOff + 1 >= fciOff + fciLen) {
      logger.warn(PARSE_ERROR + "String_Node_Str" + "String_Node_Str");
      return null;
    }
  delta=RTPUtils.readInt16AsInt(fciBuf,currentDeltaOff);
currentDeltaOff+=2;
break;
case SYMBOL_NOT_RECEIVED:
delta=-1;
break;
default :
logger.warn(PARSE_ERROR + "String_Node_Str" + symbol);
return null;
}
if (delta == -1) {
if (includeNotReceived) {
logPacket(currentSeq,NEGATIVE_ONE,delta,symbol);
packets.put(currentSeq,NEGATIVE_ONE);
}
}
 else {
referenceTime+=delta;
logPacket(currentSeq,referenceTime,delta,symbol);
packets.put(currentSeq,referenceTime);
}
currentSeq=(currentSeq + 1) & 0xffff;
}
}
currentPscOff+=CHUNK_SIZE_BYTES;
packetsRemaining-=packetsInChunk;
}
if (packetsRemaining > 0) {
logger.warn("String_Node_Str" + "String_Node_Str");
}
return packets;
}