Program: 107551
Project: 107551
Buggy source:
/** 
 * Rewrites or restores an RTP or an RTCP packet.
 * @param streamRTPManager the target {@link StreamRTPManagerDesc}.
 * @param write true if the packet is going to be written, false otherwise.
 * @param rewrite true to rewrite the packet, false to restore it.
 * @param buf the byte buffer that contains the RTP/RTCP packet.
 * @param off the offset in the byte buffer where the RTP/RTCP packetstarts.
 * @param len the number of bytes in buffer which constitute the actualdata.
 * @return true if the packet was modified, false otherwise
 */
private boolean rewritePacket(StreamRTPManagerDesc streamRTPManager,boolean write,boolean rewrite,byte[] buf,int off,int len){
  if (_data) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    ResumableStreamRewriter rewriter=streamRTPManager.streamRTPManager.getResumableStreamRewriter(ssrc,true);
    return rewrite ? rewriter.rewriteRTP(write,buf,off,len) : rewriter.restoreRTP(buf,off,len);
  }
 else {
    int offset=off, length=len;
    boolean modified=false;
    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=streamRTPManager.streamRTPManager.getResumableStreamRewriter(ssrc,false);
        if (rewriter != null) {
          boolean mod=rewriter.processRTCP(rewrite,buf,offset,pktLen);
          if (mod) {
            modified=mod;
          }
        }
      }
      offset+=pktLen;
      length-=pktLen;
    }
    return modified;
  }
}

Fixed version (ground truth):
/** 
 * Rewrites or restores an RTP or an RTCP packet.
 * @param streamRTPManager the target {@link StreamRTPManagerDesc}.
 * @param write true if the packet is going to be written, false otherwise.
 * @param rewrite true to rewrite the packet, false to restore it.
 * @param buf the byte buffer that contains the RTP/RTCP packet.
 * @param off the offset in the byte buffer where the RTP/RTCP packetstarts.
 * @param len the number of bytes in buffer which constitute the actualdata.
 * @return true if the packet was modified, false otherwise
 */
private boolean rewritePacket(StreamRTPManagerDesc streamRTPManager,boolean write,boolean rewrite,byte[] buf,int off,int len){
  if (_data) {
    Long ssrc=RawPacket.getSSRCAsLong(buf,off,len);
    ResumableStreamRewriter rewriter=streamRTPManager.streamRTPManager.getResumableStreamRewriter(ssrc,true);
    return rewrite ? rewriter.rewriteRTP(write,buf,off,len) : rewriter.restoreRTP(buf,off,len);
  }
 else {
    int offset=off, length=len;
    boolean modified=false;
    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=streamRTPManager.streamRTPManager.getResumableStreamRewriter(ssrc,false);
        if (rewriter != null) {
          boolean mod=rewriter.processRTCP(rewrite,buf,offset,pktLen);
          if (mod) {
            modified=mod;
          }
        }
      }
      offset+=pktLen;
      length-=pktLen;
    }
    return modified;
  }
}