[FFmpeg-devel] [PATCH v2 12/13] cbs_mpeg2.c: improve readability of start code search (part 2)

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Feb 5 04:24:05 EET 2022


Scott Theisen:
> If the last four bytes form a valid start code, the loop would run another time.
> Since (start == buf_end), start_code is invalidated so the loop terminates.
> 
> However, calling avpriv_find_start_code() with p == end, it will immediately
> return due to the zero size buffer.  Thus the history is not needed.
> ---
>  libavcodec/cbs_mpeg2.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
> index f2efedde5d..bf95fb7546 100644
> --- a/libavcodec/cbs_mpeg2.c
> +++ b/libavcodec/cbs_mpeg2.c
> @@ -168,8 +168,9 @@ static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx,
>              // the next unit will be treated as the last unit.
>              start_code = 0;
>          }
> -
> -        end = avpriv_find_start_code(start, buf_end, &start_code, 0);
> +        else {
> +            end = avpriv_find_start_code(start, buf_end, &start_code, 1);
> +        }
>          start--;
>          // decrement so start points to the byte containing the start_code_identifier
>          // (may be the last byte of fragment->data); end points to the byte

end is now uninitialized in case of a unit consisting solely of a
Sequence End.

- Andreas


More information about the ffmpeg-devel mailing list