[FFmpeg-devel] [PATCH] avcodec/mjpegdec: check that component index is positive

Anton Khirnov anton at khirnov.net
Mon Sep 26 11:30:35 EEST 2022


Quoting Paul B Mahol (2022-09-25 19:16:43)
> Patch attached
> 
> From 0a28ae573654d05ef56cafbb169674b1829f0c6f Mon Sep 17 00:00:00 2001
> From: Paul B Mahol <onemda at gmail.com>
> Date: Sun, 25 Sep 2022 19:17:25 +0200
> Subject: [PATCH] avcodec/mjpegdec: check that index is not negative
> 
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  libavcodec/mjpegdec.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index c594950500..57c7c1c80d 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -374,6 +374,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
>      for (i = 0; i < nb_components; i++) {
>          /* component id */
>          s->component_id[i] = get_bits(&s->gb, 8) - 1;
> +        if (s->component_id[i] < 0)

It's generally safer to not leave invalid values lying around, so better
to first check and only then write into the context.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list