PR #26114 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26114 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26114.patch
>From 4252cdb2485e214381e32089d4b08a9d99691bba Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 19:10:29 +0100 Subject: [PATCH 1/2] avcodec/pgssubdec: reject object data lengths smaller than the dimension fields The object data length includes the 4 bytes of width and height. A smaller length wrapped around and was only rejected by the allocation failing with ENOMEM. --- libavcodec/pgssubdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index 3a4b60f419b..af1c9536d8d 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -236,7 +236,7 @@ static int parse_object_segment(AVCodecContext *avctx, PGSSubObject *object; uint8_t sequence_desc; - unsigned int rle_bitmap_len, width, height; + int rle_bitmap_len, width, height; int id; if (buf_size <= 4) -- 2.54.0 >From 53f1e8faeecd5ae8b0522e695713de946216d360 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 19:16:28 +0100 Subject: [PATCH 2/2] avcodec/pgssubdec: allocate the object buffer as the object data arrives Fixes: excessive memory allocation Fixes: arH7mH3swjtk Fixes: acf_d0c5bc7e8a9c409c5d914a42bbae06af Excessive memory allocation Replicated through UnModified FFmpeg with GNU time (maximum resident set size) no further issues found with 26841009 iterations of tools/target_dec_fuzzer --- libavcodec/pgssubdec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index af1c9536d8d..3addd5a7560 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -265,7 +265,14 @@ static int parse_object_segment(AVCodecContext *avctx, if (buf_size > object->rle_remaining_len) return AVERROR_INVALIDDATA; + uint8_t *rle = av_fast_realloc(object->rle, &object->rle_buffer_size, + object->rle_data_len + buf_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!rle) + return AVERROR(ENOMEM); + object->rle = rle; + memcpy(object->rle + object->rle_data_len, buf, buf_size); + memset(object->rle + object->rle_data_len + buf_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); object->rle_data_len += buf_size; object->rle_remaining_len -= buf_size; @@ -299,7 +306,7 @@ static int parse_object_segment(AVCodecContext *avctx, object->w = width; object->h = height; - av_fast_padded_malloc(&object->rle, &object->rle_buffer_size, rle_bitmap_len); + av_fast_padded_malloc(&object->rle, &object->rle_buffer_size, buf_size); if (!object->rle) { object->rle_data_len = 0; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
