Program: 107648
Project: 107648
Buggy source:
/** 
 * Decodes an Opus packet
 * @param inBuffer input <tt>Buffer</tt>
 * @param outBuffer output <tt>Buffer</tt>
 * @return <tt>BUFFER_PROCESSED_OK</tt> if <tt>inBuffer</tt> has beensuccessfully processed
 * @see AbstractCodecExt#doProcess(Buffer,Buffer)
 */
protected int doProcess(Buffer inBuffer,Buffer outBuffer){
  Format inFormat=inBuffer.getFormat();
  if ((inFormat != null) && (inFormat != this.inputFormat) && !inFormat.equals(this.inputFormat)&& (null == setInputFormat(inFormat))) {
    return BUFFER_PROCESSED_FAILED;
  }
  long seqNo=inBuffer.getSequenceNumber();
  boolean decodeFEC=false;
  if ((lastSeqNo != Buffer.SEQUENCE_UNKNOWN) && (seqNo != lastSeqNo + 1) && (seqNo > lastSeqNo)&& (lastFrameSizeInSamplesPerChannel > 0)) {
    decodeFEC=true;
  }
  if ((inBuffer.getFlags() & Buffer.FLAG_SKIP_FEC) != 0) {
    decodeFEC=false;
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + seqNo + "String_Node_Str");
    }
  }
  byte[] in=(byte[])inBuffer.getData();
  int inOffset=inBuffer.getOffset();
  int inLength=inBuffer.getLength();
  int outOffset=0;
  int outLength=0;
  int totalFrameSizeInSamplesPerChannel=0;
  if (decodeFEC) {
    byte[] out=validateByteArraySize(outBuffer,outOffset + lastFrameSizeInSamplesPerChannel * outputFrameSize,outOffset != 0);
    int frameSizeInSamplesPerChannel=Opus.decode(decoder,in,inOffset,inLength,out,lastFrameSizeInSamplesPerChannel,1);
    if (frameSizeInSamplesPerChannel > 0) {
      int frameSizeInBytes=frameSizeInSamplesPerChannel * outputFrameSize;
      outLength+=frameSizeInBytes;
      outOffset+=frameSizeInBytes;
      totalFrameSizeInSamplesPerChannel+=frameSizeInSamplesPerChannel;
      outBuffer.setFlags(outBuffer.getFlags() | BUFFER_FLAG_FEC);
      nbDecodedFec++;
    }
    lastSeqNo++;
    if (lastSeqNo > 65535)     lastSeqNo=0;
  }
 else {
    int frameSizeInSamplesPerChannel=Opus.decoder_get_nb_samples(decoder,in,inOffset,inLength);
    byte[] out=validateByteArraySize(outBuffer,outOffset + frameSizeInSamplesPerChannel * outputFrameSize,outOffset != 0);
    frameSizeInSamplesPerChannel=Opus.decode(decoder,in,inOffset,inLength,out,frameSizeInSamplesPerChannel,0);
    if (frameSizeInSamplesPerChannel > 0) {
      int frameSizeInBytes=frameSizeInSamplesPerChannel * outputFrameSize;
      outLength+=frameSizeInBytes;
      outOffset+=frameSizeInBytes;
      totalFrameSizeInSamplesPerChannel+=frameSizeInSamplesPerChannel;
      outBuffer.setFlags(outBuffer.getFlags() & ~BUFFER_FLAG_FEC);
      lastFrameSizeInSamplesPerChannel=frameSizeInSamplesPerChannel;
    }
    lastSeqNo=seqNo;
  }
  if (outLength > 0) {
    outBuffer.setDuration(totalFrameSizeInSamplesPerChannel * channels * 1000L* 1000L / outputSampleRate);
    outBuffer.setFormat(getOutputFormat());
    outBuffer.setLength(outLength);
    outBuffer.setOffset(0);
  }
 else {
    outBuffer.setLength(0);
    discardOutputBuffer(outBuffer);
  }
  if (lastSeqNo == seqNo)   return BUFFER_PROCESSED_OK;
 else   return INPUT_BUFFER_NOT_CONSUMED;
}

Fixed version (ground truth):
/** 
 * Decodes an Opus packet
 * @param inBuffer input <tt>Buffer</tt>
 * @param outBuffer output <tt>Buffer</tt>
 * @return <tt>BUFFER_PROCESSED_OK</tt> if <tt>inBuffer</tt> has beensuccessfully processed
 * @see AbstractCodecExt#doProcess(Buffer,Buffer)
 */
protected int doProcess(Buffer inBuffer,Buffer outBuffer){
  Format inFormat=inBuffer.getFormat();
  if ((inFormat != null) && (inFormat != this.inputFormat) && !inFormat.equals(this.inputFormat)&& (null == setInputFormat(inFormat))) {
    return BUFFER_PROCESSED_FAILED;
  }
  long seqNo=inBuffer.getSequenceNumber();
  int lostSeqNoCount=calculateLostSeqNoCount(lastSeqNo,seqNo);
  boolean decodeFEC=((lostSeqNoCount != 0) && (lastFrameSizeInSamplesPerChannel != 0));
  if ((inBuffer.getFlags() & Buffer.FLAG_SKIP_FEC) != 0) {
    decodeFEC=false;
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + seqNo + "String_Node_Str");
    }
  }
  byte[] in=(byte[])inBuffer.getData();
  int inOffset=inBuffer.getOffset();
  int inLength=inBuffer.getLength();
  int outOffset=0;
  int outLength=0;
  int totalFrameSizeInSamplesPerChannel=0;
  if (decodeFEC) {
    inLength=(lostSeqNoCount == 1) ? inLength : 0;
    byte[] out=validateByteArraySize(outBuffer,outOffset + lastFrameSizeInSamplesPerChannel * outputFrameSize,outOffset != 0);
    int frameSizeInSamplesPerChannel=Opus.decode(decoder,in,inOffset,inLength,out,lastFrameSizeInSamplesPerChannel,1);
    if (frameSizeInSamplesPerChannel > 0) {
      int frameSizeInBytes=frameSizeInSamplesPerChannel * outputFrameSize;
      outLength+=frameSizeInBytes;
      outOffset+=frameSizeInBytes;
      totalFrameSizeInSamplesPerChannel+=frameSizeInSamplesPerChannel;
      outBuffer.setFlags(outBuffer.getFlags() | (((in == null) || (inLength == 0)) ? BUFFER_FLAG_PLC : BUFFER_FLAG_FEC));
      nbDecodedFec++;
    }
    lastSeqNo=incrementSeqNo(lastSeqNo);
  }
 else {
    int frameSizeInSamplesPerChannel=Opus.decoder_get_nb_samples(decoder,in,inOffset,inLength);
    byte[] out=validateByteArraySize(outBuffer,outOffset + frameSizeInSamplesPerChannel * outputFrameSize,outOffset != 0);
    frameSizeInSamplesPerChannel=Opus.decode(decoder,in,inOffset,inLength,out,frameSizeInSamplesPerChannel,0);
    if (frameSizeInSamplesPerChannel > 0) {
      int frameSizeInBytes=frameSizeInSamplesPerChannel * outputFrameSize;
      outLength+=frameSizeInBytes;
      outOffset+=frameSizeInBytes;
      totalFrameSizeInSamplesPerChannel+=frameSizeInSamplesPerChannel;
      outBuffer.setFlags(outBuffer.getFlags() & ~(BUFFER_FLAG_FEC | BUFFER_FLAG_PLC));
      lastFrameSizeInSamplesPerChannel=frameSizeInSamplesPerChannel;
    }
    lastSeqNo=seqNo;
  }
  if (outLength > 0) {
    outBuffer.setDuration(totalFrameSizeInSamplesPerChannel * channels * 1000L* 1000L / outputSampleRate);
    outBuffer.setFormat(getOutputFormat());
    outBuffer.setLength(outLength);
    outBuffer.setOffset(0);
  }
 else {
    outBuffer.setLength(0);
    discardOutputBuffer(outBuffer);
  }
  if (lastSeqNo == seqNo)   return BUFFER_PROCESSED_OK;
 else   return INPUT_BUFFER_NOT_CONSUMED;
}