[FFmpeg-trac] #4445(undetermined:new): H264 with VUI overread fails to decode

FFmpeg trac at avcodec.org
Wed Apr 8 22:51:42 CEST 2015


#4445: H264 with VUI overread fails to decode
-------------------------------------+-------------------------------------
             Reporter:  michael      |                    Owner:
                 Type:  defect       |                   Status:  new
             Priority:  normal       |                Component:
              Version:  git-master   |  undetermined
             Keywords:  h264         |               Resolution:
             Blocking:               |               Blocked By:
Analyzed by developer:  0            |  Reproduced by developer:  0
-------------------------------------+-------------------------------------

Comment (by michael):

 Can you try if this fixes it ?

 {{{
 diff --git a/libavcodec/h264.c b/libavcodec/h264.c
 index b4c4cd9..5669da5 100644
 --- a/libavcodec/h264.c
 +++ b/libavcodec/h264.c
 @@ -1629,7 +1629,9 @@ again:
                  break;
              case NAL_SPS:
                  init_get_bits(&h->gb, ptr, bit_length);
 -                if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc
 ? nalsize : 1)) {
 +                if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
 +                    break;
 +                if (h->is_avc ? nalsize : 1) {
                      av_log(h->avctx, AV_LOG_DEBUG,
                             "SPS decoding failure, trying again with the
 complete NAL\n");
                      if (h->is_avc)
 @@ -1638,8 +1640,11 @@ again:
                          break;
                      init_get_bits(&h->gb, &buf[buf_index + 1 - consumed],
                                    8*(next_avc - buf_index + consumed -
 1));
 -                    ff_h264_decode_seq_parameter_set(h);
 +                    if (ff_h264_decode_seq_parameter_set(h, 0) >= 0)
 +                        break;
                  }
 +                init_get_bits(&h->gb, ptr, bit_length);
 +                ff_h264_decode_seq_parameter_set(h, 1);

                  break;
              case NAL_PPS:
 diff --git a/libavcodec/h264.h b/libavcodec/h264.h
 index 29bb3fb..8cee11f 100644
 --- a/libavcodec/h264.h
 +++ b/libavcodec/h264.h
 @@ -812,7 +812,7 @@ int ff_h264_decode_sei(H264Context *h);
  /**
   * Decode SPS
   */
 -int ff_h264_decode_seq_parameter_set(H264Context *h);
 +int ff_h264_decode_seq_parameter_set(H264Context *h, int
 ignore_truncation);

  /**
   * compute profile from sps
 diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
 index 516c68f..19d1aa3 100644
 --- a/libavcodec/h264_parser.c
 +++ b/libavcodec/h264_parser.c
 @@ -282,7 +282,7 @@ static inline int parse_nal_units(AVCodecParserContext
 *s,
          init_get_bits(&h->gb, ptr, 8 * dst_length);
          switch (h->nal_unit_type) {
          case NAL_SPS:
 -            ff_h264_decode_seq_parameter_set(h);
 +            ff_h264_decode_seq_parameter_set(h, 0);
              break;
          case NAL_PPS:
              ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
 diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
 index ac316ac..490cd20 100644
 --- a/libavcodec/h264_ps.c
 +++ b/libavcodec/h264_ps.c
 @@ -297,7 +297,7 @@ static void decode_scaling_matrices(H264Context *h,
 SPS *sps,
      }
  }

 -int ff_h264_decode_seq_parameter_set(H264Context *h)
 +int ff_h264_decode_seq_parameter_set(H264Context *h, int
 ignore_truncation)
  {
      int profile_idc, level_idc, constraint_set_flags = 0;
      unsigned int sps_id;
 @@ -518,9 +518,10 @@ int ff_h264_decode_seq_parameter_set(H264Context *h)
      }

      if (get_bits_left(&h->gb) < 0) {
 -        av_log(h->avctx, AV_LOG_ERROR,
 +        av_log(h->avctx, ignore_truncation ? AV_LOG_WARNING :
 AV_LOG_ERROR,
                 "Overread %s by %d bits\n",
 sps->vui_parameters_present_flag ? "VUI" : "SPS", -get_bits_left(&h->gb));
 -        goto fail;
 +        if (!ignore_truncation)
 +            goto fail;
      }

      if (!sps->sar.den)

 }}}

--
Ticket URL: <https://trac.ffmpeg.org/ticket/4445#comment:4>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list