Program: 94731
Project: 94731
Buggy source:
NALUChunk assembleNALUChunk(byte[] buffer,int bufferLength){
  final byte nalHeaderByte=buffer[12];
  final int forbiddenBit=(nalHeaderByte & 0x80) >> 7;
  if (forbiddenBit != 0) {
    Timber.w("String_Node_Str");
    return null;
  }
  long rtpTimestamp=0;
  rtpTimestamp|=(buffer[4] & 0xffl) << 24;
  rtpTimestamp|=(buffer[5] & 0xffl) << 16;
  rtpTimestamp|=(buffer[6] & 0xffl) << 8;
  rtpTimestamp|=(buffer[7] & 0xffl);
  final int sequenceNumber=((buffer[2] & 0xff) << 8) | (buffer[3] & 0xff);
  final int nalType=nalHeaderByte & 0x1f;
  if (nalType <= 0) {
    Timber.d("String_Node_Str" + nalType);
    return null;
  }
  if (nalType <= 23) {
    final int payloadOffset=12;
    final int payloadLength=bufferLength - payloadOffset;
switch (nalType) {
case 7:
case 8:
{
        ByteBuffer naluData;
        if (nalType == NALUChunk.SPS_NAL_TYPE) {
          naluData=paramsNaluChunk.payloads[SPS_BUFFER_INDEX];
          isSpsSet=true;
        }
 else {
          naluData=paramsNaluChunk.payloads[PPS_BUFFER_INDEX];
          isPpsSet=true;
        }
        naluData.reset();
        naluData.put(buffer,payloadOffset,payloadLength);
        if (areParametersSet()) {
          paramsNaluChunk.sequenceNumber=sequenceNumber;
          paramsNaluChunk.presentationTime=rtpTimestamp;
          return paramsNaluChunk;
        }
        return null;
      }
default :
    if (!areParametersSet())     return null;
  ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.reset();
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
assembledNaluChunk.type=nalType;
assembledNaluChunk.sequenceNumber=sequenceNumber;
assembledNaluChunk.flags=0;
assembledNaluChunk.presentationTime=rtpTimestamp;
return assembledNaluChunk;
}
}
if (nalType == 28) {
if (!areParametersSet()) return null;
final int payloadOffset=14;
final int payloadLength=bufferLength - payloadOffset;
final int fuIndicatorByte=nalHeaderByte;
final int fuHeaderByte=buffer[13];
final int fuNalType=fuHeaderByte & 0x1f;
final int startBit=(fuHeaderByte & 0x80) >> 7;
final int endBit=(fuHeaderByte & 0x40) >> 6;
if (startBit == 1) {
ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.reset();
assembledNaluBuffer.put((byte)((fuIndicatorByte & 0xe0) | fuNalType));
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
boolean isConfig=fuNalType == 7 || fuNalType == 8;
assembledNaluChunk.sequenceNumber=sequenceNumber;
assembledNaluChunk.type=fuNalType;
assembledNaluChunk.flags=isConfig ? MediaCodec.BUFFER_FLAG_CODEC_CONFIG : 0;
assembledNaluChunk.presentationTime=rtpTimestamp;
return null;
}
 else {
if (sequenceNumber - 1 != assembledNaluChunk.sequenceNumber) {
return null;
}
ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
assembledNaluChunk.sequenceNumber=sequenceNumber;
if (endBit == 1) {
return assembledNaluChunk;
}
 else {
return null;
}
}
}
return null;
}

Fixed version (ground truth):
NALUChunk assembleNALUChunk(byte[] buffer,int bufferLength){
  final byte nalHeaderByte=buffer[12];
  final int forbiddenBit=(nalHeaderByte & 0x80) >> 7;
  if (forbiddenBit != 0) {
    Timber.w("String_Node_Str");
    return null;
  }
  long rtpTimestamp=0;
  rtpTimestamp|=(buffer[4] & 0xffl) << 24;
  rtpTimestamp|=(buffer[5] & 0xffl) << 16;
  rtpTimestamp|=(buffer[6] & 0xffl) << 8;
  rtpTimestamp|=(buffer[7] & 0xffl);
  final int sequenceNumber=((buffer[2] & 0xff) << 8) | (buffer[3] & 0xff);
  final int nalType=nalHeaderByte & 0x1f;
  if (nalType <= 0) {
    Timber.d("String_Node_Str" + nalType);
    return null;
  }
  if (prevSeq != -1) {
    final int expectedSeq=prevSeq + 1;
    if (sequenceNumber != expectedSeq) {
      Timber.v("String_Node_Str",expectedSeq,sequenceNumber);
    }
  }
  prevSeq=sequenceNumber;
  if (nalType <= 23) {
    final int payloadOffset=12;
    final int payloadLength=bufferLength - payloadOffset;
switch (nalType) {
case 7:
case 8:
{
        ByteBuffer naluData;
        if (nalType == NALUChunk.SPS_NAL_TYPE) {
          naluData=paramsNaluChunk.payloads[SPS_BUFFER_INDEX];
          isSpsSet=true;
        }
 else {
          naluData=paramsNaluChunk.payloads[PPS_BUFFER_INDEX];
          isPpsSet=true;
        }
        naluData.reset();
        naluData.put(buffer,payloadOffset,payloadLength);
        if (areParametersSet()) {
          paramsNaluChunk.sequenceNumber=sequenceNumber;
          paramsNaluChunk.presentationTime=0;
          return paramsNaluChunk;
        }
        return null;
      }
default :
    if (!areParametersSet())     return null;
  ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.reset();
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
assembledNaluChunk.type=nalType;
assembledNaluChunk.sequenceNumber=sequenceNumber;
assembledNaluChunk.flags=0;
assembledNaluChunk.presentationTime=naluCounter++ * DELTA_PRESENTATION_TIME;
return assembledNaluChunk;
}
}
if (nalType == 28) {
if (!areParametersSet()) return null;
final int payloadOffset=14;
final int payloadLength=bufferLength - payloadOffset;
final int fuIndicatorByte=nalHeaderByte;
final int fuHeaderByte=buffer[13];
final int fuNalType=fuHeaderByte & 0x1f;
final int startBit=(fuHeaderByte & 0x80) >> 7;
final int endBit=(fuHeaderByte & 0x40) >> 6;
if (startBit == 1) {
ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.reset();
assembledNaluBuffer.put((byte)((fuIndicatorByte & 0xe0) | fuNalType));
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
boolean isConfig=fuNalType == 7 || fuNalType == 8;
assembledNaluChunk.sequenceNumber=sequenceNumber;
assembledNaluChunk.type=fuNalType;
assembledNaluChunk.flags=isConfig ? MediaCodec.BUFFER_FLAG_CODEC_CONFIG : 0;
return null;
}
 else {
if (sequenceNumber - 1 != assembledNaluChunk.sequenceNumber) {
return null;
}
ByteBuffer assembledNaluBuffer=assembledNaluChunk.payloads[0];
assembledNaluBuffer.put(buffer,payloadOffset,payloadLength);
assembledNaluChunk.sequenceNumber=sequenceNumber;
if (endBit == 1) {
assembledNaluChunk.presentationTime=naluCounter++ * DELTA_PRESENTATION_TIME;
return assembledNaluChunk;
}
 else {
return null;
}
}
}
return null;
}