[FFmpeg-devel] [PATCH] avcodec/mjpegdec: Adjustable discard threshold

Andriy Gelman andriy.gelman at gmail.com
Sun Jun 27 20:38:01 EEST 2021


On Sun, 27. Jun 15:53, Michael Niedermayer wrote:
> Fixes regression
> Fixes: last frame of Ticket9287
> 
> Analysed-by: Andriy Gelman
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
>  libavcodec/mjpegdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 02a987fd0c..fbc94c46d7 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -338,7 +338,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
>      av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
>      if (av_image_check_size(width, height, 0, s->avctx) < 0)
>          return AVERROR_INVALIDDATA;
> -    if (s->buf_size && (width + 7) / 8 * ((height + 7) / 8) > s->buf_size * 4LL)
> +    if (s->buf_size && (width + 7) / 8 * ((height + 7) / 8) * (100LL - s->avctx->discard_damaged_percentage) > s->buf_size * 4LL * 100)
>          return AVERROR_INVALIDDATA;
>  
>      nb_components = get_bits(&s->gb, 8);

Would a check for discard_damaged_percentage be more accurate in the mjpeg_decode_scan() function?
Because mapping buf_size to the number of decoded pixels seems only an estimate at
this point.

As I understand the goal of this check was to initially prevent timeouts from
the fuzzer. The timeouts were caused because there were lots of SOF markers with
large frames (so there were many calls to ff_get_buffer()), without SOS markers being called.

If the goal is prevent timeout, would it be better to somehow delay calling ff_get_buffer() until we actually
start to decode the pixels?   
I think this was actually done in c8197f73e684b0edc450f3dc2b2b4b3fb9dedd0d, but was reverted recently.

-- 
Andriy


More information about the ffmpeg-devel mailing list