Program: 13800
Project: 13800
Buggy source:
public int decode_nal_units(int[] buf_base,int buf_offset,int buf_size){
  int buf_index=0;
  H264Context hx=this;
  int context_count=0;
  int next_avc=((this.is_avc != 0) ? 0 : buf_size);
  this.max_contexts=1;
  if (0 == (s.flags2 & MpegEncContext.CODEC_FLAG2_CHUNKS)) {
    this.current_slice=0;
    if (0 == s.first_field)     s.current_picture_ptr=null;
    SEIDecoder.ff_h264_reset_sei(this);
  }
  for (; ; ) {
    int consumed;
    int dst_length;
    int bit_length;
    int[] ptr_base;
    int ptr_offset;
    int i, nalsize=0;
    int err;
    if (buf_index >= next_avc) {
      if (buf_index >= buf_size)       break;
      nalsize=0;
      for (i=0; i < this.nal_length_size; i++)       nalsize=(nalsize << 8) | buf_base[buf_offset + buf_index++];
      if (nalsize <= 0 || nalsize > buf_size - buf_index) {
        break;
      }
      next_avc=buf_index + nalsize;
    }
 else {
      for (; buf_index + 3 < next_avc; buf_index++) {
        if (buf_base[buf_offset + buf_index] == 0 && buf_base[buf_offset + buf_index + 1] == 0 && buf_base[buf_offset + buf_index + 2] == 1)         break;
      }
      if (buf_index + 3 >= buf_size)       break;
      buf_index+=3;
      if (buf_index >= next_avc)       continue;
    }
    hx=this.thread_context[context_count];
    int[] param=new int[3];
    ptr_base=hx.ff_h264_decode_nal(buf_base,buf_offset + buf_index,param,next_avc - buf_index);
    dst_length=param[0];
    consumed=param[1];
    ptr_offset=param[2];
    if (ptr_base == null || dst_length < 0) {
      return -1;
    }
    i=buf_index + consumed;
    if ((s.workaround_bugs & MpegEncContext.FF_BUG_AUTODETECT) != 0 && i + 3 < next_avc && buf_base[buf_offset + i] == 0x00 && buf_base[buf_offset + i + 1] == 0x00 && buf_base[buf_offset + i + 2] == 0x01 && buf_base[buf_offset + i + 3] == 0x0E0)     s.workaround_bugs|=MpegEncContext.FF_BUG_TRUNCATED;
    if (0 == (s.workaround_bugs & MpegEncContext.FF_BUG_TRUNCATED)) {
      while (ptr_base[ptr_offset + dst_length - 1] == 0 && dst_length > 0)       dst_length--;
    }
    bit_length=(dst_length == 0) ? 0 : (8 * dst_length - ff_h264_decode_rbsp_trailing(ptr_base,ptr_offset + dst_length - 1));
    if (this.is_avc != 0 && (nalsize != consumed) && nalsize != 0) {
    }
    buf_index+=consumed;
    if ((s.hurry_up == 1 && this.nal_ref_idc == 0) || (s.skip_frame >= MpegEncContext.AVDISCARD_NONREF && this.nal_ref_idc == 0))     continue;
    boolean doAgain=false;
    do {
      doAgain=false;
      err=0;
switch (hx.nal_unit_type) {
case NAL_IDR_SLICE:
        if (this.nal_unit_type != NAL_IDR_SLICE) {
          return -1;
        }
      idr();
case NAL_SLICE:
    hx.s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
  hx.intra_gb_ptr=hx.inter_gb_ptr=hx.s.gb;
hx.s.data_partitioning=0;
err=decode_slice_header(hx,this);
if ((err) != 0) break;
if (this.current_slice == 1) {
}
s.current_picture_ptr.key_frame|=(((hx.nal_unit_type == NAL_IDR_SLICE) || (this.sei_recovery_frame_cnt >= 0)) ? 1 : 0);
if (hx.redundant_pic_count == 0 && hx.s.hurry_up < 5 && (s.skip_frame < MpegEncContext.AVDISCARD_NONREF || hx.nal_ref_idc != 0) && (s.skip_frame < MpegEncContext.AVDISCARD_BIDIR || hx.slice_type_nos != FF_B_TYPE) && (s.skip_frame < MpegEncContext.AVDISCARD_NONKEY || hx.slice_type_nos == FF_I_TYPE) && s.skip_frame < MpegEncContext.AVDISCARD_ALL) {
if (s.hwaccel != 0) {
}
 else {
context_count++;
}
}
break;
case NAL_DPA:
hx.s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.intra_gb_ptr=hx.inter_gb_ptr=null;
err=decode_slice_header(hx,this);
if ((err) < 0) break;
hx.s.data_partitioning=1;
break;
case NAL_DPB:
hx.intra_gb=new GetBitContext();
hx.intra_gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.intra_gb_ptr=hx.intra_gb;
break;
case NAL_DPC:
hx.inter_gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.inter_gb_ptr=hx.inter_gb;
if (hx.redundant_pic_count == 0 && hx.intra_gb_ptr != null && hx.s.data_partitioning != 0 && s.context_initialized != 0 && s.hurry_up < 5 && (s.skip_frame < MpegEncContext.AVDISCARD_NONREF || hx.nal_ref_idc != 0) && (s.skip_frame < MpegEncContext.AVDISCARD_BIDIR || hx.slice_type_nos != FF_B_TYPE) && (s.skip_frame < MpegEncContext.AVDISCARD_NONKEY || hx.slice_type_nos == FF_I_TYPE) && s.skip_frame < MpegEncContext.AVDISCARD_ALL) {
context_count++;
}
break;
case NAL_SEI:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_sei();
break;
case NAL_SPS:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_seq_parameter_set();
if ((s.flags & MpegEncContext.CODEC_FLAG_LOW_DELAY) != 0) s.low_delay=1;
if (s.has_b_frames < 2) s.has_b_frames=((0 == s.low_delay) ? 1 : 0);
break;
case NAL_PPS:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_picture_parameter_set(bit_length);
break;
case NAL_AUD:
case NAL_END_SEQUENCE:
case NAL_END_STREAM:
case NAL_FILLER_DATA:
case NAL_SPS_EXT:
case NAL_AUXILIARY_SLICE:
break;
default :
}
if (context_count == this.max_contexts) {
decode_slice();
context_count=0;
}
if (err < 0) {
}
 else if (err == 1) {
this.nal_unit_type=hx.nal_unit_type;
this.nal_ref_idc=hx.nal_ref_idc;
hx=this;
doAgain=true;
}
}
 while (doAgain == true);
}
if (context_count != 0) decode_slice();
return buf_index;
}

Fixed version (ground truth):
public int decode_nal_units(int[] buf_base,int buf_offset,int buf_size){
  int buf_index=0;
  H264Context hx=this;
  int context_count=0;
  int next_avc=((this.is_avc != 0) ? 0 : buf_size);
  this.max_contexts=1;
  if (0 == (s.flags2 & MpegEncContext.CODEC_FLAG2_CHUNKS)) {
    this.current_slice=0;
    if (0 == s.first_field)     s.current_picture_ptr=null;
    SEIDecoder.ff_h264_reset_sei(this);
  }
  for (; ; ) {
    int consumed;
    int dst_length;
    int bit_length;
    int[] ptr_base;
    int ptr_offset;
    int i, nalsize=0;
    int err;
    if (buf_index >= next_avc) {
      if (buf_index >= buf_size)       break;
      nalsize=0;
      for (i=0; i < this.nal_length_size; i++)       nalsize=(nalsize << 8) | buf_base[buf_offset + buf_index++];
      if (nalsize <= 0 || nalsize > buf_size - buf_index) {
        break;
      }
      next_avc=buf_index + nalsize;
    }
 else {
      for (; buf_index + 3 < next_avc; buf_index++) {
        if (buf_base[buf_offset + buf_index] == 0 && buf_base[buf_offset + buf_index + 1] == 0 && buf_base[buf_offset + buf_index + 2] == 1)         break;
      }
      if (buf_index + 3 >= buf_size)       break;
      buf_index+=3;
      if (buf_index >= next_avc)       continue;
    }
    hx=this.thread_context[context_count];
    int[] param=new int[3];
    ptr_base=hx.ff_h264_decode_nal(buf_base,buf_offset + buf_index,param,next_avc - buf_index);
    dst_length=param[0];
    consumed=param[1];
    ptr_offset=param[2];
    if (ptr_base == null || dst_length < 0) {
      System.out.println("String_Node_Str" + ptr_base + "String_Node_Str"+ dst_length);
      return -1;
    }
    i=buf_index + consumed;
    if ((s.workaround_bugs & MpegEncContext.FF_BUG_AUTODETECT) != 0 && i + 3 < next_avc && buf_base[buf_offset + i] == 0x00 && buf_base[buf_offset + i + 1] == 0x00 && buf_base[buf_offset + i + 2] == 0x01 && buf_base[buf_offset + i + 3] == 0x0E0)     s.workaround_bugs|=MpegEncContext.FF_BUG_TRUNCATED;
    if (0 == (s.workaround_bugs & MpegEncContext.FF_BUG_TRUNCATED)) {
      while (ptr_base[ptr_offset + dst_length - 1] == 0 && dst_length > 0)       dst_length--;
    }
    bit_length=(dst_length == 0) ? 0 : (8 * dst_length - ff_h264_decode_rbsp_trailing(ptr_base,ptr_offset + dst_length - 1));
    if (this.is_avc != 0 && (nalsize != consumed) && nalsize != 0) {
      System.out.println("String_Node_Str" + consumed + "String_Node_Str"+ nalsize);
    }
    buf_index+=consumed;
    if ((s.hurry_up == 1 && this.nal_ref_idc == 0) || (s.skip_frame >= MpegEncContext.AVDISCARD_NONREF && this.nal_ref_idc == 0))     continue;
    boolean doAgain=false;
    do {
      doAgain=false;
      err=0;
switch (hx.nal_unit_type) {
case NAL_IDR_SLICE:
        if (this.nal_unit_type != NAL_IDR_SLICE) {
          System.out.println("String_Node_Str");
          return -1;
        }
      idr();
case NAL_SLICE:
    hx.s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
  hx.intra_gb_ptr=hx.inter_gb_ptr=hx.s.gb;
hx.s.data_partitioning=0;
err=decode_slice_header(hx,this);
if ((err) != 0) {
System.out.println("String_Node_Str" + err);
break;
}
s.current_picture_ptr.key_frame|=(((hx.nal_unit_type == NAL_IDR_SLICE) || (this.sei_recovery_frame_cnt >= 0)) ? 1 : 0);
if (hx.redundant_pic_count == 0 && hx.s.hurry_up < 5 && (s.skip_frame < MpegEncContext.AVDISCARD_NONREF || hx.nal_ref_idc != 0) && (s.skip_frame < MpegEncContext.AVDISCARD_BIDIR || hx.slice_type_nos != FF_B_TYPE) && (s.skip_frame < MpegEncContext.AVDISCARD_NONKEY || hx.slice_type_nos == FF_I_TYPE) && s.skip_frame < MpegEncContext.AVDISCARD_ALL) {
if (s.hwaccel != 0) {
System.out.println("String_Node_Str");
}
 else {
context_count++;
}
}
break;
case NAL_DPA:
hx.s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.intra_gb_ptr=hx.inter_gb_ptr=null;
err=decode_slice_header(hx,this);
if ((err) < 0) {
System.out.println("String_Node_Str" + err);
break;
}
hx.s.data_partitioning=1;
break;
case NAL_DPB:
hx.intra_gb=new GetBitContext();
hx.intra_gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.intra_gb_ptr=hx.intra_gb;
break;
case NAL_DPC:
hx.inter_gb.init_get_bits(ptr_base,ptr_offset,bit_length);
hx.inter_gb_ptr=hx.inter_gb;
if (hx.redundant_pic_count == 0 && hx.intra_gb_ptr != null && hx.s.data_partitioning != 0 && s.context_initialized != 0 && s.hurry_up < 5 && (s.skip_frame < MpegEncContext.AVDISCARD_NONREF || hx.nal_ref_idc != 0) && (s.skip_frame < MpegEncContext.AVDISCARD_BIDIR || hx.slice_type_nos != FF_B_TYPE) && (s.skip_frame < MpegEncContext.AVDISCARD_NONKEY || hx.slice_type_nos == FF_I_TYPE) && s.skip_frame < MpegEncContext.AVDISCARD_ALL) {
context_count++;
}
break;
case NAL_SEI:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_sei();
break;
case NAL_SPS:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_seq_parameter_set();
if ((s.flags & MpegEncContext.CODEC_FLAG_LOW_DELAY) != 0) s.low_delay=1;
if (s.has_b_frames < 2) s.has_b_frames=((0 == s.low_delay) ? 1 : 0);
break;
case NAL_PPS:
s.gb.init_get_bits(ptr_base,ptr_offset,bit_length);
ff_h264_decode_picture_parameter_set(bit_length);
break;
case NAL_AUD:
case NAL_END_SEQUENCE:
case NAL_END_STREAM:
case NAL_FILLER_DATA:
case NAL_SPS_EXT:
case NAL_AUXILIARY_SLICE:
break;
default :
System.out.println("String_Node_Str" + hx.nal_unit_type + "String_Node_Str"+ bit_length);
}
if (context_count == this.max_contexts) {
decode_slice();
context_count=0;
}
if (err < 0) {
System.out.println("String_Node_Str" + err);
}
 else if (err == 1) {
this.nal_unit_type=hx.nal_unit_type;
this.nal_ref_idc=hx.nal_ref_idc;
hx=this;
doAgain=true;
}
}
 while (doAgain == true);
}
if (context_count != 0) decode_slice();
return buf_index;
}