nus-yam/ex-repair huggingface dataset:
Program: 107523
Project: 107523
Buggy source:
/** 
 * Increments the   {@link #filterState} as a result of accepting the packetspecified in the arguments.
 * @param buf the <tt>byte</tt> array that holds the RTP packet.
 * @param off the offset in <tt>buffer</tt> at which the actual RTP databegins.
 * @param len the number of <tt>byte</tt>s in <tt>buffer</tt> whichconstitute the actual RTP data.
 */
private void onAccept(byte[] buf,int off,int len){
  long ts=transformState.tsTranslation.apply(RawPacket.getTimestamp(buf,off,len));
  if (filterState.maxTs == -1 || TimeUtils.rtpDiff(ts,filterState.maxTs) > 0) {
    filterState.maxTs=ts;
  }
  int seqNum=transformState.seqNumTranslation.apply(RawPacket.getSequenceNumber(buf,off,len));
  if (filterState.maxSeqNum == -1 || RTPUtils.sequenceNumberDiff(seqNum,filterState.maxSeqNum) > 0) {
    filterState.maxSeqNum=seqNum;
  }
  filterState.transmittedBytes+=len;
  filterState.transmittedPackets++;
}

Fixed version (ground truth):
/** 
 * Increments the   {@link #filterState} as a result of accepting the packetspecified in the arguments.
 * @param buf the <tt>byte</tt> array that holds the RTP packet.
 * @param off the offset in <tt>buffer</tt> at which the actual RTP databegins.
 * @param len the number of <tt>byte</tt>s in <tt>buffer</tt> whichconstitute the actual RTP data.
 */
private void onAccept(byte[] buf,int off,int len){
  long ts=context.tsTranslation.apply(RawPacket.getTimestamp(buf,off,len));
  if (filterState.maxTs == -1 || TimeUtils.rtpDiff(ts,filterState.maxTs) > 0) {
    filterState.maxTs=ts;
  }
  int seqNum=context.seqNumTranslation.apply(RawPacket.getSequenceNumber(buf,off,len));
  if (filterState.maxSeqNum == -1 || RTPUtils.sequenceNumberDiff(seqNum,filterState.maxSeqNum) > 0) {
    filterState.maxSeqNum=seqNum;
  }
  filterState.transmittedBytes+=len;
  filterState.transmittedPackets++;
}
Program: 107524
Project: 107524
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public Bitrates getBitrates(){
  long currentBps=0;
  MediaStreamTrackDesc source=weakSource.get();
  if (source == null) {
    return Bitrates.EMPTY;
  }
  RTPEncodingDesc[] sourceEncodings=source.getRTPEncodings();
  if (ArrayUtils.isNullOrEmpty(sourceEncodings)) {
    return Bitrates.EMPTY;
  }
  int currentIdx=transformState.currentIdx;
  if (currentIdx != -1) {
    if (sourceEncodings[currentIdx].isActive()) {
      currentBps=sourceEncodings[currentIdx].getLastStableBitrateBps();
    }
  }
  long optimalBps=0;
  int optimalIdx=this.optimalIdx;
  if (optimalIdx >= 0) {
    for (int i=optimalIdx; i > -1; i--) {
      if (!sourceEncodings[i].isActive()) {
        continue;
      }
      long bps=sourceEncodings[i].getLastStableBitrateBps();
      if (bps > 0) {
        optimalBps=bps;
        break;
      }
    }
  }
  return new Bitrates(currentBps,optimalBps);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public Bitrates getBitrates(){
  long currentBps=0;
  MediaStreamTrackDesc source=weakSource.get();
  if (source == null) {
    return Bitrates.EMPTY;
  }
  RTPEncodingDesc[] sourceEncodings=source.getRTPEncodings();
  if (ArrayUtils.isNullOrEmpty(sourceEncodings)) {
    return Bitrates.EMPTY;
  }
  int currentIdx=context.currentIdx;
  if (currentIdx != -1) {
    if (sourceEncodings[currentIdx].isActive()) {
      currentBps=sourceEncodings[currentIdx].getLastStableBitrateBps();
    }
  }
  long optimalBps=0;
  int optimalIdx=this.optimalIdx;
  if (optimalIdx >= 0) {
    for (int i=optimalIdx; i > -1; i--) {
      if (!sourceEncodings[i].isActive()) {
        continue;
      }
      long bps=sourceEncodings[i].getLastStableBitrateBps();
      if (bps > 0) {
        optimalBps=bps;
        break;
      }
    }
  }
  return new Bitrates(currentBps,optimalBps);
}
Program: 107526
Project: 107526
Buggy source:
/** 
 * Updates this   {@link MediaStreamTrackReceiver} with the new RTP encodingparameters.
 * @param newTracks the {@link MediaStreamTrackDesc}s that this instance will receive.
 * @return true if the MSTs have changed, otherwise false.
 */
public boolean setMediaStreamTracks(MediaStreamTrackDesc[] newTracks){
  MediaStreamTrackDesc[] oldTracks=tracks;
  int oldTracksLen=oldTracks == null ? 0 : oldTracks.length;
  int newTracksLen=newTracks == null ? 0 : newTracks.length;
  if (oldTracksLen == 0 || newTracksLen == 0) {
    tracks=newTracks;
    return oldTracksLen != newTracksLen;
  }
 else {
    int cntMatched=0;
    MediaStreamTrackDesc[] mergedTracks=new MediaStreamTrackDesc[newTracks.length];
    for (int i=0; i < newTracks.length; i++) {
      RTPEncodingDesc newEncoding=newTracks[i].getRTPEncodings()[0];
      for (int j=0; i < oldTracks.length; j++) {
        if (oldTracks[j] != null && oldTracks[j].matches(newEncoding.getPrimarySSRC())) {
          mergedTracks[i]=oldTracks[j];
          cntMatched++;
          break;
        }
      }
      if (mergedTracks[i] == null) {
        mergedTracks[i]=newTracks[i];
      }
    }
    tracks=mergedTracks;
    return oldTracksLen != newTracksLen || cntMatched != oldTracks.length;
  }
}

Fixed version (ground truth):
/** 
 * Updates this   {@link MediaStreamTrackReceiver} with the new RTP encodingparameters.
 * @param newTracks the {@link MediaStreamTrackDesc}s that this instance will receive.
 * @return true if the MSTs have changed, otherwise false.
 */
public boolean setMediaStreamTracks(MediaStreamTrackDesc[] newTracks){
  MediaStreamTrackDesc[] oldTracks=tracks;
  int oldTracksLen=oldTracks == null ? 0 : oldTracks.length;
  int newTracksLen=newTracks == null ? 0 : newTracks.length;
  if (oldTracksLen == 0 || newTracksLen == 0) {
    tracks=newTracks;
    return oldTracksLen != newTracksLen;
  }
 else {
    int cntMatched=0;
    MediaStreamTrackDesc[] mergedTracks=new MediaStreamTrackDesc[newTracks.length];
    for (int i=0; i < newTracks.length; i++) {
      RTPEncodingDesc newEncoding=newTracks[i].getRTPEncodings()[0];
      for (int j=0; j < oldTracks.length; j++) {
        if (oldTracks[j] != null && oldTracks[j].matches(newEncoding.getPrimarySSRC())) {
          mergedTracks[i]=oldTracks[j];
          cntMatched++;
          break;
        }
      }
      if (mergedTracks[i] == null) {
        mergedTracks[i]=newTracks[i];
      }
    }
    tracks=mergedTracks;
    return oldTracksLen != newTracksLen || cntMatched != oldTracks.length;
  }
}
Program: 107527
Project: 107527
Buggy source:
@Override public void setOffsetLength(int offset,int length){
  if (offset + length > buffer.length) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.offset=offset;
}

Fixed version (ground truth):
@Override public void setOffsetLength(int offset,int length){
  if (offset + length > buffer.length) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.offset=offset;
  this.length=length;
}
Program: 107529
Project: 107529
Buggy source:
/** 
 * Ctor.
 * @param rtpEncoding the {@link RTPEncodingImpl} that this instance belongsto.
 */
SourceFrameDesc(RTPEncodingImpl rtpEncoding){
  this.rtpEncoding=rtpEncoding;
}

Fixed version (ground truth):
/** 
 * Ctor.
 * @param rtpEncoding the {@link RTPEncodingImpl} that this instance belongsto.
 * @param ts the RTP timestamp for this frame.
 */
SourceFrameDesc(RTPEncodingImpl rtpEncoding,long ts){
  this.rtpEncoding=rtpEncoding;
  this.ts=ts;
}
Program: 107530
Project: 107530
Buggy source:
/** 
 * Returns   {@code true} if the packet with timestamp {@code timestamp}arrived in order.
 * @param timestamp
 * @return
 */
private boolean isPacketInOrder(long timestamp){
  if (currentTimestampGroup.isFirstPacket()) {
    return true;
  }
 else {
    long timestampDiff=timestamp - currentTimestampGroup.firstTimestamp;
    return timestampDiff < 0x80000000L;
  }
}

Fixed version (ground truth):
/** 
 * Returns   {@code true} if the packet with timestamp {@code timestamp}arrived in order.
 * @param timestamp
 * @return
 */
private boolean isPacketInOrder(long timestamp){
  if (currentTimestampGroup.isFirstPacket()) {
    return true;
  }
 else {
    long timestampDiff=subtractAsUnsignedInt32(timestamp,currentTimestampGroup.firstTimestamp);
    return timestampDiff < 0x80000000L;
  }
}
Program: 107531
Project: 107531
Buggy source:
/** 
 * webrtc/modules/include/module_common_types.h
 * @param timestamp1
 * @param timestamp2
 * @return
 */
private static long latestTimestamp(long timestamp1,long timestamp2){
  return isNewerTimestamp(timestamp1,timestamp2) ? timestamp1 : timestamp2;
}

Fixed version (ground truth):
/** 
 * webrtc/modules/include/module_common_types.h
 * @param timestamp1
 * @param timestamp2
 * @return
 */
static long latestTimestamp(long timestamp1,long timestamp2){
  return isNewerTimestamp(timestamp1,timestamp2) ? timestamp1 : timestamp2;
}
Program: 107532
Project: 107532
Buggy source:
/** 
 * webrtc/modules/include/module_common_types.h
 * @param timestamp
 * @param prevTimestamp
 * @return
 */
private static boolean isNewerTimestamp(long timestamp,long prevTimestamp){
  if (timestamp - prevTimestamp == 0x80000000L) {
    return timestamp > prevTimestamp;
  }
  return timestamp != prevTimestamp && timestamp - prevTimestamp < 0x80000000L;
}

Fixed version (ground truth):
/** 
 * webrtc/modules/include/module_common_types.h
 * @param timestamp
 * @param prevTimestamp
 * @return
 */
static boolean isNewerTimestamp(long timestamp,long prevTimestamp){
  if (subtractAsUnsignedInt32(timestamp,prevTimestamp) == 0x80000000L) {
    return timestamp > prevTimestamp;
  }
  return timestamp != prevTimestamp && subtractAsUnsignedInt32(timestamp,prevTimestamp) < 0x80000000L;
}
Program: 107533
Project: 107533
Buggy source:
/** 
 * {@inheritDoc}bitrate_controller_impl.cc BitrateControllerImpl::OnReceivedRtcpReceiverReport
 */
@Override public void rtcpReportReceived(RTCPReport report){
  if (report == null || report.getFeedbackReports() == null || report.getFeedbackReports().isEmpty()) {
    return;
  }
  long total_number_of_packets=0;
  long fraction_lost_aggregate=0;
  for (  RTCPFeedback feedback : report.getFeedbackReports()) {
    long ssrc=feedback.getSSRC();
    long extSeqNum=feedback.getXtndSeqNum();
    Long lastEHSN=ssrc_to_last_received_extended_high_seq_num_.get(ssrc);
    if (lastEHSN == null) {
      lastEHSN=extSeqNum;
      continue;
    }
    ssrc_to_last_received_extended_high_seq_num_.put(ssrc,extSeqNum);
    if (lastEHSN >= extSeqNum) {
      continue;
    }
    long number_of_packets=extSeqNum - lastEHSN;
    fraction_lost_aggregate+=number_of_packets * feedback.getFractionLost();
    total_number_of_packets+=number_of_packets;
  }
  if (total_number_of_packets == 0) {
    fraction_lost_aggregate=0;
  }
 else {
    fraction_lost_aggregate=(fraction_lost_aggregate + total_number_of_packets / 2) / total_number_of_packets;
  }
  if (fraction_lost_aggregate > 255) {
    return;
  }
synchronized (sendSideBandwidthEstimation) {
    lastUpdateTime=System.currentTimeMillis();
    sendSideBandwidthEstimation.updateReceiverBlock(fraction_lost_aggregate,total_number_of_packets,lastUpdateTime);
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}bitrate_controller_impl.cc BitrateControllerImpl::OnReceivedRtcpReceiverReport
 */
@Override public void rtcpReportReceived(RTCPReport report){
  if (report == null || report.getFeedbackReports() == null || report.getFeedbackReports().isEmpty()) {
    return;
  }
  long total_number_of_packets=0;
  long fraction_lost_aggregate=0;
  for (  RTCPFeedback feedback : report.getFeedbackReports()) {
    long ssrc=feedback.getSSRC();
    long extSeqNum=feedback.getXtndSeqNum();
    Long lastEHSN=ssrc_to_last_received_extended_high_seq_num_.get(ssrc);
    if (lastEHSN == null) {
      lastEHSN=extSeqNum;
    }
    ssrc_to_last_received_extended_high_seq_num_.put(ssrc,extSeqNum);
    if (lastEHSN >= extSeqNum) {
      continue;
    }
    long number_of_packets=extSeqNum - lastEHSN;
    fraction_lost_aggregate+=number_of_packets * feedback.getFractionLost();
    total_number_of_packets+=number_of_packets;
  }
  if (total_number_of_packets == 0) {
    fraction_lost_aggregate=0;
  }
 else {
    fraction_lost_aggregate=(fraction_lost_aggregate + total_number_of_packets / 2) / total_number_of_packets;
  }
  if (fraction_lost_aggregate > 255) {
    return;
  }
synchronized (sendSideBandwidthEstimation) {
    lastUpdateTime=System.currentTimeMillis();
    sendSideBandwidthEstimation.updateReceiverBlock(fraction_lost_aggregate,total_number_of_packets,lastUpdateTime);
  }
}
Program: 107534
Project: 107534
Buggy source:
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=(buf[extensionOffset++] & 0xFF) << 8 | (buf[extensionOffset++] & 0xFF);
  int lengthInBytes=4 * (1 + lengthInWords);
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=(buf[extensionOffset++] & 0xFF) << 8 | (buf[extensionOffset++] & 0xFF);
  int lengthInBytes=4 * lengthInWords;
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}
Program: 107535
Project: 107535
Buggy source:
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=(buf[extensionOffset++] & 0xFF) << 8 | (buf[extensionOffset++] & 0xFF);
  int lengthInBytes=4 * (1 + lengthInWords);
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=(buf[extensionOffset++] & 0xFF) << 8 | (buf[extensionOffset++] & 0xFF);
  int lengthInBytes=4 * lengthInWords;
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}
Program: 107536
Project: 107536
Buggy source:
private static boolean verifyStapANaluLengths(byte[] data,int offset,int lengthRemaining){
  int initialLength=lengthRemaining;
  while (lengthRemaining > 0 && offset + 1 < initialLength) {
    if (lengthRemaining < kNalUSize) {
      return false;
    }
    int naluSize=data[offset] << 8 | data[offset + 1];
    offset+=kNalUSize;
    lengthRemaining-=kNalUSize;
    if (naluSize > lengthRemaining) {
      return false;
    }
    offset+=naluSize;
    lengthRemaining-=naluSize;
  }
  return true;
}

Fixed version (ground truth):
private static boolean verifyStapANaluLengths(byte[] data,int offset,int lengthRemaining){
  int initialLength=lengthRemaining;
  while (lengthRemaining > 0 && offset + 1 < initialLength && offset > 0) {
    if (lengthRemaining < kNalUSize) {
      return false;
    }
    int naluSize=data[offset] << 8 | data[offset + 1];
    offset+=kNalUSize;
    lengthRemaining-=kNalUSize;
    if (naluSize > lengthRemaining) {
      return false;
    }
    offset+=naluSize;
    lengthRemaining-=naluSize;
  }
  return true;
}
Program: 107537
Project: 107537
Buggy source:
/** 
 * Gets the <tt>Buffer</tt> instance responsible for buffering packets with SSRC <tt>ssrc</tt>. Creates it if necessary, always returns non-null.
 * @param ssrc the SSRC for which go get a <tt>Buffer</tt>.
 * @return the <tt>Buffer</tt> instance responsible for buffering packets withSSRC <tt>ssrc</tt>. Creates it if necessary, always returns non-null.
 */
private Buffer getBuffer(long ssrc){
  Buffer buffer=buffers.get(ssrc);
  if (buffer == null) {
synchronized (buffers) {
      buffer=buffers.get(ssrc);
      if (buffer == null) {
        buffer=new Buffer(SIZE,ssrc);
        buffers.put(ssrc,buffer);
      }
    }
  }
  return buffer;
}

Fixed version (ground truth):
/** 
 * Gets the <tt>Buffer</tt> instance responsible for buffering packets with SSRC <tt>ssrc</tt>. Creates it if necessary, always returns non-null.
 * @param ssrc the SSRC for which go get a <tt>Buffer</tt>.
 * @return the <tt>Buffer</tt> instance responsible for buffering packets withSSRC <tt>ssrc</tt>. Creates it if necessary, always returns non-null.
 */
private Buffer getBuffer(long ssrc){
synchronized (buffers) {
    Buffer buffer=buffers.get(ssrc);
    if (buffer == null) {
      buffer=new Buffer(SIZE,ssrc);
      buffers.put(ssrc,buffer);
    }
    return buffer;
  }
}
Program: 107538
Project: 107538
Buggy source:
/** 
 * Empties the <tt>Buffer</tt> for a specific SSRC, and returns its contents as an ordered (by RTP sequence number) array.
 * @param ssrc the SSRC for which to empty the <tt>Buffer</tt>.
 * @return the contents of the <tt>Buffer</tt> for SSRC, or an empty array,if there is no buffer for SSRC.
 */
RawPacket[] emptyBuffer(long ssrc){
  Buffer buffer=buffers.get(ssrc);
  if (buffer != null) {
    return buffer.empty();
  }
  return new RawPacket[0];
}

Fixed version (ground truth):
/** 
 * Empties the <tt>Buffer</tt> for a specific SSRC, and returns its contents as an ordered (by RTP sequence number) array.
 * @param ssrc the SSRC for which to empty the <tt>Buffer</tt>.
 * @return the contents of the <tt>Buffer</tt> for SSRC, or an empty array,if there is no buffer for SSRC.
 */
RawPacket[] emptyBuffer(long ssrc){
  Buffer buffer;
synchronized (buffers) {
    buffer=buffers.get(ssrc);
  }
  if (buffer != null) {
    return buffer.empty();
  }
  return new RawPacket[0];
}
Program: 107539
Project: 107539
Buggy source:
/** 
 * Resets the buffer for a particular SSRC (effectively re-enabling it if it was disabled).
 * @param ssrc
 */
void reset(long ssrc){
synchronized (buffers) {
    Buffer buffer=buffers.get(ssrc);
    if (buffer != null)     buffers.remove(ssrc);
  }
}

Fixed version (ground truth):
/** 
 * Resets the buffer for a particular SSRC (effectively re-enabling it if it was disabled).
 * @param ssrc
 */
void reset(long ssrc){
synchronized (buffers) {
    buffers.remove(ssrc);
  }
}
Program: 107540
Project: 107540
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void close(){
  for (  FECReceiver fecReceiver : fecReceivers.values())   fecReceiver.close();
  for (  FECSender fecSender : fecSenders.values())   fecSender.close();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void close(){
  Collection<FECReceiver> receivers;
  Collection<FECSender> senders;
synchronized (fecReceivers) {
    receivers=fecReceivers.values();
    fecReceivers.clear();
  }
synchronized (fecSenders) {
    senders=fecSenders.values();
    fecSenders.clear();
  }
  for (  FECReceiver fecReceiver : receivers)   fecReceiver.close();
  for (  FECSender fecSender : senders)   fecSender.close();
}
Program: 107541
Project: 107541
Buggy source:
/** 
 * Removes the RTP-NTP mapping for a given SSRC.
 * @param ssrc the SSRC for which to remove the RTP-NTP mapping
 */
void removeMapping(long ssrc){
  if (ssrcs.containsKey(ssrc)) {
synchronized (ssrcs) {
      SSRCDesc ssrcDesc=ssrcs.get(ssrc);
      if (ssrcDesc != null) {
synchronized (ssrcDesc) {
          ssrcDesc.ntpTime=-1.0;
          ssrcDesc.rtpTime=-1;
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Removes the RTP-NTP mapping for a given SSRC.
 * @param ssrc the SSRC for which to remove the RTP-NTP mapping
 */
void removeMapping(long ssrc){
  SSRCDesc ssrcDesc=ssrcs.get(ssrc);
  if (ssrcDesc != null) {
synchronized (ssrcDesc) {
      ssrcDesc.ntpTime=-1.0;
      ssrcDesc.rtpTime=-1;
    }
  }
}
Program: 107542
Project: 107542
Buggy source:
/** 
 * Returns the <tt>Endpoint</tt> with id <tt>endpointId</tt>. Creates an <tt>Endpoint</tt> if necessary. Always returns non-null.
 * @param endpointId the string identifying the endpoint.
 * @return the <tt>Endpoint</tt> with id <tt>endpointId</tt>. Creates an<tt>Endpoint</tt> if necessary.
 */
private Endpoint getEndpoint(String endpointId){
  Endpoint endpoint=endpoints.get(endpointId);
  if (endpoint == null) {
synchronized (endpoints) {
      endpoint=endpoints.get(endpointId);
      if (endpoint == null) {
        endpoint=new Endpoint();
        endpoints.put(endpointId,endpoint);
      }
    }
  }
  return endpoint;
}

Fixed version (ground truth):
/** 
 * Returns the <tt>Endpoint</tt> with id <tt>endpointId</tt>. Creates an <tt>Endpoint</tt> if necessary. Always returns non-null.
 * @param endpointId the string identifying the endpoint.
 * @return the <tt>Endpoint</tt> with id <tt>endpointId</tt>. Creates an<tt>Endpoint</tt> if necessary.
 */
private Endpoint getEndpoint(String endpointId){
synchronized (endpoints) {
    Endpoint endpoint=endpoints.get(endpointId);
    if (endpoint == null) {
      endpoint=new Endpoint();
      endpoints.put(endpointId,endpoint);
    }
    return endpoint;
  }
}
Program: 107543
Project: 107543
Buggy source:
/** 
 * Return a set of all items with type CNAME from the RTCP SDES packet <tt>pkt</tt>.
 * @param pkt the packet to parse for CNAME items.
 * @retur a set of all items with type CNAME from the RTCP SDES packet<tt>pkt</tt>.
 */
private Set<CNAMEItem> getCnameItems(RawPacket pkt){
  Set<CNAMEItem> ret=new HashSet<CNAMEItem>();
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int len=pkt.getLength();
  int ptr=4;
  while (ptr + 6 < len) {
    int type=buf[off + ptr + 4];
    int len2=buf[off + ptr + 5];
    if (ptr + 6 + len2 >= len)     break;
    if (type == 1) {
      CNAMEItem item=new CNAMEItem();
      item.ssrc=readUnsignedIntAsLong(buf,off + ptr);
      item.cname=readString(buf,off + ptr + 6,len2);
      ret.add(item);
    }
    ptr+=6 + len2;
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Return a set of all items with type CNAME from the RTCP SDES packet <tt>pkt</tt>.
 * @param pkt the packet to parse for CNAME items.
 * @return a set of all items with type CNAME from the RTCP SDES packet<tt>pkt</tt>.
 */
private Set<CNAMEItem> getCnameItems(RawPacket pkt){
  Set<CNAMEItem> ret=new HashSet<>();
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int len=pkt.getLength();
  int ptr=4;
  while (ptr + 6 < len) {
    int type=buf[off + ptr + 4];
    int len2=buf[off + ptr + 5];
    if (ptr + 6 + len2 >= len)     break;
    if (type == 1) {
      CNAMEItem item=new CNAMEItem();
      item.ssrc=readUnsignedIntAsLong(buf,off + ptr);
      item.cname=readString(buf,off + ptr + 6,len2);
      ret.add(item);
    }
    ptr+=6 + len2;
  }
  return ret;
}
Program: 107544
Project: 107544
Buggy source:
/** 
 * Returns the <tt>SSRCDesc</tt> instance mapped to the SSRC <tt>ssrc</tt>. If no instance is mapped to <tt>ssrc</tt>, create one and inserts it in the map. Always returns non-null.
 * @param ssrc the ssrc to get the <tt>SSRCDesc</tt> for.
 * @return the <tt>SSRCDesc</tt> instance mapped to the SSRC <tt>ssrc</tt>.
 */
private SSRCDesc getSSRCDesc(long ssrc){
  SSRCDesc ssrcDesc=ssrcs.get(ssrc);
  if (ssrcDesc == null) {
synchronized (ssrcs) {
      ssrcDesc=ssrcs.get(ssrc);
      if (ssrcDesc == null) {
        ssrcDesc=new SSRCDesc();
        ssrcs.put(ssrc,ssrcDesc);
      }
    }
  }
  return ssrcDesc;
}

Fixed version (ground truth):
/** 
 * Returns the <tt>SSRCDesc</tt> instance mapped to the SSRC <tt>ssrc</tt>. If no instance is mapped to <tt>ssrc</tt>, create one and inserts it in the map. Always returns non-null.
 * @param ssrc the ssrc to get the <tt>SSRCDesc</tt> for.
 * @return the <tt>SSRCDesc</tt> instance mapped to the SSRC <tt>ssrc</tt>.
 */
private SSRCDesc getSSRCDesc(long ssrc){
synchronized (ssrcs) {
    SSRCDesc ssrcDesc=ssrcs.get(ssrc);
    if (ssrcDesc == null) {
      ssrcDesc=new SSRCDesc();
      ssrcs.put(ssrc,ssrcDesc);
    }
    return ssrcDesc;
  }
}
Program: 107545
Project: 107545
Buggy source:
/** 
 * Computes the sum of the values of a specific   {@code Map} with{@code Long} values.
 * @param map the {@code Map} with {@code Long} values to sum up
 * @return the sum of the values of the specified {@code map}
 */
private static long getCumulativeValue(Map<?,Long> map){
  long cumulativeValue=0;
  for (  Long value : map.values()) {
    if (value == null)     continue;
    cumulativeValue+=value;
  }
  return cumulativeValue;
}

Fixed version (ground truth):
/** 
 * Computes the sum of the values of a specific   {@code Map} with{@code Long} values.
 * @param map the {@code Map} with {@code Long} values to sum up. Note thatwe synchronize on this object!
 * @return the sum of the values of the specified {@code map}
 */
private static long getCumulativeValue(Map<?,Long> map){
  long cumulativeValue=0;
synchronized (map) {
    for (    Long value : map.values()) {
      if (value == null)       continue;
      cumulativeValue+=value;
    }
  }
  return cumulativeValue;
}
Program: 107546
Project: 107546
Buggy source:
/** 
 * Utility method to return a value from a map and perform unboxing only if the result value is not null.
 * @param map the map to get the value
 * @param ssrc the key
 * @return the result value or 0 if nothing is found.
 */
private static long getMapValue(Map<?,Long> map,long ssrc){
  Long res=map.get(ssrc);
  return res == null ? 0 : res;
}

Fixed version (ground truth):
/** 
 * Utility method to return a value from a map and perform unboxing only if the result value is not null.
 * @param map the map to get the value. Note that we synchronize on thatobject!
 * @param ssrc the key
 * @return the result value or 0 if nothing is found.
 */
private static long getMapValue(Map<?,Long> map,long ssrc){
synchronized (map) {
    Long res=map.get(ssrc);
    return res == null ? 0 : res;
  }
}
Program: 107547
Project: 107547
Buggy source:
/** 
 * Utility method to increment map value with specified step. If entry is missing add it.
 * @param map the map holding the values
 * @param ssrc the key of the value to increment
 * @param step increment step value
 */
private static void incrementSSRCCounter(Map<Long,Long> map,long ssrc,long step){
  Long count=map.get(ssrc);
  map.put(ssrc,(count == null) ? step : (count + step));
}

Fixed version (ground truth):
/** 
 * Utility method to increment map value with specified step. If entry is missing add it.
 * @param map the map holding the values. Note that we synchronize on thatobject!
 * @param ssrc the key of the value to increment
 * @param step increment step value
 */
private static void incrementSSRCCounter(Map<Long,Long> map,long ssrc,long step){
synchronized (map) {
    Long count=map.get(ssrc);
    map.put(ssrc,(count == null) ? step : (count + step));
  }
}
Program: 107548
Project: 107548
Buggy source:
/** 
 * Ctor.
 * @param highestSequenceNumberSent the highest sequence number that gotaccepted, mod 2^16.
 * @param seqnumDelta the seqnumDelta between what's been accepted andwhat's been received, mod 2^16.
 * @param highestTimestampSent The highest timestamp that got accepted,mod 2^32.
 * @param timestampDelta The timestamp delta between what's been acceptedand what's been received, mod 2^32.
 */
public ResumableStreamRewriter(int highestSequenceNumberSent,int seqnumDelta,long highestTimestampSent,long timestampDelta){
  this.seqnumDelta=seqnumDelta;
  this.highestSequenceNumberSent=highestSequenceNumberSent;
  this.highestTimestampSent=highestTimestampSent;
  this.timestampDelta=timestampDelta;
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + highestSequenceNumberSent + "String_Node_Str"+ seqnumDelta+ "String_Node_Str"+ highestTimestampSent+ "String_Node_Str"+ timestampDelta);
  }
}

Fixed version (ground truth):
/** 
 * Ctor.
 * @param highestSequenceNumberSent the highest sequence number that gotaccepted, mod 2^16.
 * @param seqnumDelta the seqnumDelta between what's been accepted andwhat's been received, mod 2^16.
 * @param highestTimestampSent The highest timestamp that got accepted,mod 2^32.
 * @param timestampDelta The timestamp delta between what's been acceptedand what's been received, mod 2^32.
 */
public ResumableStreamRewriter(int highestSequenceNumberSent,int seqnumDelta,long highestTimestampSent,long timestampDelta){
  this.seqnumDelta=seqnumDelta;
  this.highestSequenceNumberSent=highestSequenceNumberSent;
  this.highestTimestampSent=highestTimestampSent;
  this.timestampDelta=timestampDelta;
  if (DEBUG) {
    logger.debug("String_Node_Str" + highestSequenceNumberSent + "String_Node_Str"+ seqnumDelta+ "String_Node_Str"+ highestTimestampSent+ "String_Node_Str"+ timestampDelta);
  }
}
Program: 107549
Project: 107549
Buggy source:
/** 
 * Rewrites the sequence number of the RTP packet in the byte buffer, hiding any gaps caused by drops.
 * @param accept true if the packet is accepted, false otherwise
 * @param buf the byte buffer that contains the RTP packet
 * @param off the offset in the byte buffer where the RTP packet starts
 * @param len the length of the RTP packet in the byte buffer
 * @return true if the packet was altered, false otherwise
 */
public boolean rewriteRTP(boolean accept,byte[] buf,int off,int len){
  if (buf == null || buf.length + off < len) {
    return false;
  }
  int sequenceNumber=RawPacket.getSequenceNumber(buf,off,len);
  int newSequenceNumber=rewriteSequenceNumber(accept,sequenceNumber);
  long timestamp=RawPacket.getTimestamp(buf,off,len);
  long newTimestamp=rewriteTimestamp(accept,timestamp);
  boolean modified=false;
  if (sequenceNumber != newSequenceNumber) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str" + ssrc + "String_Node_Str"+ sequenceNumber+ "String_Node_Str"+ newSequenceNumber);
    }
    RawPacket.setSequenceNumber(buf,off,newSequenceNumber);
    modified=true;
  }
  if (timestamp != newTimestamp) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str" + ssrc + "String_Node_Str"+ timestamp+ "String_Node_Str"+ newTimestamp);
    }
    RawPacket.setTimestamp(buf,off,len,newTimestamp);
    modified=true;
  }
  return modified;
}

Fixed version (ground truth):
/** 
 * Rewrites the sequence number of the RTP packet in the byte buffer, hiding any gaps caused by drops.
 * @param accept true if the packet is accepted, false otherwise
 * @param buf the byte buffer that contains the RTP packet
 * @param off the offset in the byte buffer where the RTP packet starts
 * @param len the length of the RTP packet in the byte buffer
 * @return true if the packet was altered, false otherwise
 */
public boolean rewriteRTP(boolean accept,byte[] buf,int off,int len){
  if (buf == null || buf.length < off + len) {
    return false;
  }
  int sequenceNumber=RawPacket.getSequenceNumber(buf,off,len);
  int newSequenceNumber=rewriteSequenceNumber(accept,sequenceNumber);
  long timestamp=RawPacket.getTimestamp(buf,off,len);
  long newTimestamp=rewriteTimestamp(accept,timestamp);
  boolean modified=false;
  if (sequenceNumber != newSequenceNumber) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    if (DEBUG) {
      logger.debug("String_Node_Str" + ssrc + "String_Node_Str"+ sequenceNumber+ "String_Node_Str"+ newSequenceNumber);
    }
    RawPacket.setSequenceNumber(buf,off,newSequenceNumber);
    modified=true;
  }
  if (timestamp != newTimestamp) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    if (DEBUG) {
      logger.debug("String_Node_Str" + ssrc + "String_Node_Str"+ timestamp+ "String_Node_Str"+ newTimestamp);
    }
    RawPacket.setTimestamp(buf,off,len,newTimestamp);
    modified=true;
  }
  return modified;
}
Program: 107550
Project: 107550
Buggy source:
/** 
 * Restores the RTP timestamp of the RTCP SR packet in the buffer.
 * @param buf the byte buffer that contains the RTCP packet.
 * @param off the offset in the byte buffer where the RTCP packet starts.
 * @param len the number of bytes in buffer which constitute the actualdata.
 * @return true if the SR is modified, false otherwise.
 */
public boolean processRTCP(boolean rewrite,byte[] buf,int off,int len){
  if (timestampDelta == 0) {
    return false;
  }
  long ts=RTCPSenderInfoUtils.getTimestamp(buf,off,len);
  if (ts == -1) {
    return false;
  }
  long newTs=rewrite ? (ts - timestampDelta) & 0xffffffffL : (ts + timestampDelta) & 0xffffffffL;
  boolean ret=RTCPSenderInfoUtils.setTimestamp(buf,off,len,newTs);
  return ret;
}

Fixed version (ground truth):
/** 
 * Restores the RTP timestamp of the RTCP SR packet in the buffer.
 * @param buf the byte buffer that contains the RTCP packet.
 * @param off the offset in the byte buffer where the RTCP packet starts.
 * @param len the number of bytes in buffer which constitute the actualdata.
 * @return true if the SR is modified, false otherwise.
 */
public boolean processRTCP(boolean rewrite,byte[] buf,int off,int len){
  if (timestampDelta == 0) {
    return false;
  }
  long ts=RTCPSenderInfoUtils.getTimestamp(buf,off,len);
  if (ts == -1) {
    return false;
  }
  long newTs=rewrite ? (ts - timestampDelta) & 0xffffffffL : (ts + timestampDelta) & 0xffffffffL;
  if (DEBUG) {
    logger.debug("String_Node_Str" + ts + "String_Node_Str"+ newTs);
  }
  boolean ret=RTCPSenderInfoUtils.setTimestamp(buf,off,len,newTs);
  return ret;
}
Program: 107552
Project: 107552
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public RawPacket reverseTransform(RawPacket pkt){
  if (pkt == null) {
    return pkt;
  }
  byte[] buf=pkt.getBuffer();
  int offset=pkt.getOffset(), length=pkt.getLength();
  while (length > 0) {
    if (RTCPHeaderUtils.isValid(buf,offset,length)) {
      break;
    }
    int pktLen=RTCPHeaderUtils.getLength(buf,offset,length);
    int pt=RTCPHeaderUtils.getPacketType(buf,offset,pktLen);
    if (pt == RTCPPacket.SR) {
      long ssrc=RTCPHeaderUtils.getSenderSSRC(buf,offset,pktLen);
      ResumableStreamRewriter rewriter=ssrcToRewriter.get(ssrc);
      if (rewriter != null) {
        rewriter.processRTCP(true,buf,offset,pktLen);
      }
    }
    offset+=pktLen;
    length-=pktLen;
  }
  return pkt;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public RawPacket reverseTransform(RawPacket pkt){
  if (pkt == null) {
    return pkt;
  }
  byte[] buf=pkt.getBuffer();
  int offset=pkt.getOffset(), length=pkt.getLength();
  while (length > 0) {
    if (!RTCPHeaderUtils.isValid(buf,offset,length)) {
      break;
    }
    int pktLen=RTCPHeaderUtils.getLength(buf,offset,length);
    int pt=RTCPHeaderUtils.getPacketType(buf,offset,pktLen);
    if (pt == RTCPPacket.SR) {
      long ssrc=RTCPHeaderUtils.getSenderSSRC(buf,offset,pktLen);
      ResumableStreamRewriter rewriter=ssrcToRewriter.get(ssrc);
      if (rewriter != null) {
        rewriter.processRTCP(true,buf,offset,pktLen);
      }
    }
    offset+=pktLen;
    length-=pktLen;
  }
  return pkt;
}
Program: 107553
Project: 107553
Buggy source:
/** 
 * Uplift the timestamp of a frame if we've already sent a larger timestamp to the remote endpoint.
 * @param p
 */
public void maybeUpliftTimestamp(RawPacket p){
  long timestamp=p.getTimestamp();
  if (maxTimestamp == -1) {
    maxTimestamp=timestamp - 1;
  }
  long minTimestamp=maxTimestamp + 1;
  long delta=TimeUtils.rtpDiff(timestamp,minTimestamp);
  if (delta < 0) {
    if (DEBUG) {
      logger.debug("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    if (delta < -300000 && WARN) {
      logger.warn("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    p.setTimestamp(minTimestamp);
  }
 else {
  }
  if (TimeUtils.rtpDiff(maxTimestamp,timestamp) < 0) {
    maxTimestamp=timestamp;
  }
}

Fixed version (ground truth):
/** 
 * Uplift the timestamp of a frame if we've already sent a larger timestamp to the remote endpoint.
 * @param p
 */
public void maybeUpliftTimestamp(RawPacket p){
  long timestamp=p.getTimestamp();
  if (maxTimestamp == -1) {
    maxTimestamp=timestamp - 1;
  }
  long minTimestamp=maxTimestamp + 1;
  long delta=TimeUtils.rtpDiff(timestamp,minTimestamp);
  if (delta < 0) {
    if (DEBUG) {
      logger.debug("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    if (delta < -300000 && WARN) {
      logger.warn("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    p.setTimestamp(minTimestamp);
    timestamp=minTimestamp;
  }
 else {
  }
  if (TimeUtils.rtpDiff(maxTimestamp,timestamp) < 0) {
    maxTimestamp=timestamp;
  }
}
Program: 107554
Project: 107554
Buggy source:
/** 
 * Uplift the timestamp of a frame if we've already sent a larger timestamp to the remote endpoint.
 * @param p
 */
public void maybeUpliftTimestamp(RawPacket p){
  long timestamp=p.getTimestamp();
  long minTimestamp=maxTimestamp + 1;
  long delta=TimeUtils.rtpDiff(timestamp,minTimestamp);
  if (delta < 0) {
    if (DEBUG) {
      logger.debug("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    if (delta < -300000 && WARN) {
      logger.warn("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    p.setTimestamp(minTimestamp);
  }
 else {
  }
  if (maxTimestamp < timestamp) {
    maxTimestamp=timestamp;
  }
}

Fixed version (ground truth):
/** 
 * Uplift the timestamp of a frame if we've already sent a larger timestamp to the remote endpoint.
 * @param p
 */
public void maybeUpliftTimestamp(RawPacket p){
  long timestamp=p.getTimestamp();
  long minTimestamp=(maxTimestamp == -1) ? timestamp : maxTimestamp + 1;
  long delta=TimeUtils.rtpDiff(timestamp,minTimestamp);
  if (delta < 0) {
    if (DEBUG) {
      logger.debug("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    if (delta < -300000 && WARN) {
      logger.warn("String_Node_Str" + timestamp + "String_Node_Str"+ p.getSequenceNumber()+ "String_Node_Str"+ p.getSSRCAsLong()+ "String_Node_Str"+ delta+ "String_Node_Str"+ minTimestamp);
    }
    p.setTimestamp(minTimestamp);
  }
 else {
  }
  if (TimeUtils.rtpDiff(maxTimestamp,timestamp) < 0) {
    maxTimestamp=timestamp;
  }
}
Program: 107555
Project: 107555
Buggy source:
/** 
 * Stop ZRTP engine. The ZRTP stack stores RS2 without the valid flag. If we close the ZRTP stream then check if we need to set RS2 to vaild. This is the case if we received less than 10 good SRTP packets. In this case we enable RS2 to make sure the ZRTP self-synchronization is active. This handling is needed to comply to an upcoming newer ZRTP RFC.
 */
public void stopZrtp(){
  if (zrtpEngine != null) {
    if (zrtpUnprotect < 10)     zrtpEngine.setRs2Valid();
    zrtpEngine.stopZrtp();
    zrtpEngine=null;
    started=false;
  }
  if (srtpOutTransformer != null) {
    srtpOutTransformer.close();
    srtpOutTransformer=null;
  }
  if (srtpInTransformer != null) {
    srtpInTransformer.close();
    srtpOutTransformer=null;
  }
  if (zrtcpTransformer != null) {
    zrtcpTransformer.close();
    zrtcpTransformer=null;
  }
}

Fixed version (ground truth):
/** 
 * Stop ZRTP engine. The ZRTP stack stores RS2 without the valid flag. If we close the ZRTP stream then check if we need to set RS2 to vaild. This is the case if we received less than 10 good SRTP packets. In this case we enable RS2 to make sure the ZRTP self-synchronization is active. This handling is needed to comply to an upcoming newer ZRTP RFC.
 */
public void stopZrtp(){
  if (zrtpEngine != null) {
    if (zrtpUnprotect < 10)     zrtpEngine.setRs2Valid();
    zrtpEngine.stopZrtp();
    zrtpEngine=null;
    started=false;
  }
  if (srtpOutTransformer != null) {
    srtpOutTransformer.close();
    srtpOutTransformer=null;
  }
  if (srtpInTransformer != null) {
    srtpInTransformer.close();
    srtpInTransformer=null;
  }
  if (zrtcpTransformer != null) {
    zrtcpTransformer.close();
    zrtcpTransformer=null;
  }
}
Program: 107556
Project: 107556
Buggy source:
@Override public REDBlock next(){
  if (!hasNext()) {
    throw new NoSuchElementException();
  }
  cntRemainingBlocks--;
  if (buffer == null || buffer.length <= offNextBlockHeader) {
    logger.warn("String_Node_Str");
    return null;
  }
  byte blockPT=(byte)(buffer[offNextBlockHeader] & 0x7f);
  int blockLen;
  if (hasNext()) {
    if (buffer.length < offNextBlockHeader + 4) {
      logger.warn("String_Node_Str");
      return null;
    }
    blockLen=(buffer[offNextBlockHeader + 2] & 0x03) << 8 | (buffer[offNextBlockHeader + 3]);
    offNextBlockHeader+=4;
    offNextBlockPayload+=blockLen;
  }
 else {
    blockLen=length - (offNextBlockPayload + 1);
    offNextBlockHeader=-1;
    offNextBlockPayload=-1;
  }
  return new REDBlock(offNextBlockPayload,blockLen,blockPT);
}

Fixed version (ground truth):
@Override public REDBlock next(){
  if (!hasNext()) {
    throw new NoSuchElementException();
  }
  cntRemainingBlocks--;
  if (buffer == null || buffer.length <= offNextBlockHeader) {
    logger.warn("String_Node_Str");
    return null;
  }
  byte blockPT=(byte)(buffer[offNextBlockHeader] & 0x7f);
  int blockLen;
  if (hasNext()) {
    if (buffer.length < offNextBlockHeader + 4) {
      logger.warn("String_Node_Str");
      return null;
    }
    blockLen=(buffer[offNextBlockHeader + 2] & 0x03) << 8 | (buffer[offNextBlockHeader + 3] & 0xFF);
    offNextBlockHeader+=4;
    offNextBlockPayload+=blockLen;
  }
 else {
    blockLen=length - (offNextBlockPayload + 1);
    offNextBlockHeader=-1;
    offNextBlockPayload=-1;
  }
  return new REDBlock(offNextBlockPayload,blockLen,blockPT);
}
Program: 107557
Project: 107557
Buggy source:
/** 
 * Checks whether <tt>pkt</tt> looks like a valid RTCP packet.
 * @param pkt the packet to check.
 * @return <tt>true</tt> if <tt>pkt</tt> seems to be a valid RTCP packet.
 */
private boolean isValidRTCP(RawPacket pkt){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int len=pkt.getLength();
  if (len < 4)   return false;
  int v=(buf[off] & 0xc0) >>> 6;
  if (v != 2)   return false;
  int lengthInWords=(buf[off + 2] << 8) + buf[off + 3];
  int lengthInBytes=(lengthInWords + 1) * 4;
  if (len < lengthInBytes)   return false;
  return true;
}

Fixed version (ground truth):
/** 
 * Checks whether <tt>pkt</tt> looks like a valid RTCP packet.
 * @param pkt the packet to check.
 * @return <tt>true</tt> if <tt>pkt</tt> seems to be a valid RTCP packet.
 */
private boolean isValidRTCP(RawPacket pkt){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int len=pkt.getLength();
  if (len < 4)   return false;
  int v=(buf[off] & 0xc0) >>> 6;
  if (v != 2)   return false;
  int lengthInWords=(buf[off + 2] & 0xFF) << 8 | (buf[off + 3] & 0xFF);
  int lengthInBytes=(lengthInWords + 1) * 4;
  if (len < lengthInBytes)   return false;
  return true;
}