PR #25963 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25963 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25963.patch
>From 30631580b7a4469ba881b753036f6a514de67d84 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 16:32:49 +0100 Subject: [PATCH 01/10] avformat/imfdec: fix the overflow check of the resource count Fixes: out of array write Fixes: spGhOOxgliHp Regression since: ef0d5245d6 Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Out of array write Replicated through UnModified FFmpeg with ASAN --- libavformat/imfdec.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 39a95366e6c..2aebdc3b8b0 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -482,9 +482,8 @@ static int open_track_file_resource(AVFormatContext *s, AV_UUID_ARG(asset_locator->uuid), asset_locator->absolute_uri); - if (track->resource_count > INT32_MAX - track_file_resource->base.repeat_count - || (track->resource_count + track_file_resource->base.repeat_count) - > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx)) + if (track_file_resource->base.repeat_count + > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx) - track->resource_count) return AVERROR(ENOMEM); tmp = av_fast_realloc(track->resources, &track->resources_alloc_sz, -- 2.54.0 >From e01d2ba754a8232fb0c3e607f90e28b44ed7ac1f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:00:22 +0100 Subject: [PATCH 02/10] avformat/imfdec: limit the number of resources of a composition Every repetition of a resource takes an entry in the resource array of its track. A RepeatCount of 44000000 needed 2 GiB for it. Fixes: excessive memory allocation Fixes: RNdiJLvrqS9c Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Excessive memory allocation Replicated through UnModified FFmpeg with time (maximum resident set size) --- libavformat/imfdec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 2aebdc3b8b0..6b4bb2ac94d 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -77,6 +77,7 @@ #define AVRATIONAL_FORMAT "%d/%d" #define AVRATIONAL_ARG(rational) rational.num, rational.den +#define MAX_RESOURCES FFMIN(1 << 20, INT_MAX / (int)sizeof(IMFVirtualTrackResourcePlaybackCtx)) /** * IMF Asset locator @@ -125,6 +126,7 @@ typedef struct IMFContext { IMFAssetLocatorMap asset_locator_map; uint32_t track_count; IMFVirtualTrackPlaybackCtx **tracks; + uint32_t total_resource_count; } IMFContext; static int imf_uri_is_url(const char *string) @@ -483,8 +485,9 @@ static int open_track_file_resource(AVFormatContext *s, asset_locator->absolute_uri); if (track_file_resource->base.repeat_count - > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx) - track->resource_count) + > MAX_RESOURCES - c->total_resource_count) return AVERROR(ENOMEM); + c->total_resource_count += track_file_resource->base.repeat_count; tmp = av_fast_realloc(track->resources, &track->resources_alloc_sz, (track->resource_count + track_file_resource->base.repeat_count) -- 2.54.0 >From bb233710631c6687f7421941c804a988e3fc93b3 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 16:33:22 +0100 Subject: [PATCH 03/10] avformat/imf_cpl: reject an EditRate that is not positive Fixes: -nan is outside the range of representable values of type 'long' Fixes: Assertion c > 0 failed at libavutil/mathematics.c Fixes: A5TJ4YnA1yYe Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Undefined behavior Replicated through UnModified FFmpeg with UBSAN --- libavformat/imf.h | 2 +- libavformat/imf_cpl.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libavformat/imf.h b/libavformat/imf.h index ef124bf4124..3cba33a7210 100644 --- a/libavformat/imf.h +++ b/libavformat/imf.h @@ -183,7 +183,7 @@ void ff_imf_cpl_free(FFIMFCPL *cpl); int ff_imf_xml_read_uint32(xmlNodePtr element, uint32_t *number); /** - * Reads an AVRational from an XML element + * Reads a positive AVRational from an XML element * @return 0 on success, < 0 AVERROR code on error. */ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational); diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c index 0edfcbec036..3846d34d777 100644 --- a/libavformat/imf_cpl.c +++ b/libavformat/imf_cpl.c @@ -90,7 +90,8 @@ int ff_imf_xml_read_rational(xmlNodePtr element, AVRational *rational) int ret = 0; xmlChar *element_text = xmlNodeListGetString(element->doc, element->xmlChildrenNode, 1); - if (element_text == NULL || sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2) + if (element_text == NULL || sscanf(element_text, "%i %i", &rational->num, &rational->den) != 2 + || rational->num <= 0 || rational->den <= 0) ret = AVERROR_INVALIDDATA; xmlFree(element_text); -- 2.54.0 >From a34501d6a8c9e9bca92dc387d0b8510522572c5b Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:00:22 +0100 Subject: [PATCH 04/10] avformat/imfdec: rescale the seek target without multiplying ints Fixes: signed integer overflow: 48000 * 1048576 cannot be represented in type 'int' Fixes: A5TJ4YnA1yYe Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Signed integer overflow Replicated through UnModified FFmpeg with UBSAN --- libavformat/imfdec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 6b4bb2ac94d..e92c9688656 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -996,9 +996,7 @@ static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, st->time_base)) av_log(s, AV_LOG_WARNING, "Seek position is not coherent across tracks\n"); - dts = av_rescale(ts, - st->time_base.den * c->cpl->edit_rate.den, - st->time_base.num * c->cpl->edit_rate.num); + dts = av_rescale_q(ts, av_inv_q(c->cpl->edit_rate), st->time_base); av_log(s, AV_LOG_DEBUG, "Seeking to dts=%" PRId64 " on stream_index=%d\n", dts, i); -- 2.54.0 >From 43cb8189522cb31ecab32f09355e6bb2a653ae29 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:00:22 +0100 Subject: [PATCH 05/10] avformat/imfdec: check the coherence of a seek target without overflow Fixes: signed integer overflow: 216000000000000 * 48000 cannot be represented in type 'int64_t' (aka 'long') Fixes: A5TJ4YnA1yYe Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Signed integer overflow Replicated through UnModified FFmpeg with UBSAN --- libavformat/imfdec.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index e92c9688656..46de8c9a9d9 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -946,16 +946,8 @@ static int imf_probe(const AVProbeData *p) static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb) { - int dst_num; - int dst_den; - int ret; - - ret = av_reduce(&dst_num, &dst_den, ts * in_tb.num * out_tb.den, - in_tb.den * out_tb.num, INT64_MAX); - if (!ret || dst_den != 1) - return 0; - - return 1; + return av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_DOWN) == + av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_UP); } static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts, -- 2.54.0 >From d3bcf5ecc3dc5fb5314ce784b4ca3ae9176b9313 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:00:22 +0100 Subject: [PATCH 06/10] avcodec/cbs_av1: limit the number of OBUs of a fragment Every decomposed OBU gets an AV1RawOBU as content, whatever its size. A packet of 2 byte OBUs needed more than 1000 times its size in memory. Limit a fragment to 65536 OBUs, the limit av1_frame_merge uses for a temporal unit. Fixes: excessive memory allocation Fixes: RJDrEhcINcH8 Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25569 Excessive memory allocation Replicated through UnModified FFmpeg with time (maximum resident set size) --- libavcodec/cbs_av1.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index e4b275199ba..71a55b658d6 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -27,6 +27,8 @@ #include "defs.h" #include "libavutil/refstruct.h" +#define MAX_FRAGMENT_OBUS (1 << 16) + #if CBS_READ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, @@ -788,6 +790,12 @@ static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, goto fail; } + if (frag->nb_units >= MAX_FRAGMENT_OBUS) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many OBUs in a fragment.\n"); + err = AVERROR_INVALIDDATA; + goto fail; + } + err = CBS_FUNC(append_unit_data)(frag, obu_header.obu_type, data, obu_length, frag->data_ref); if (err < 0) -- 2.54.0 >From 13763c7b1a17709bc873e1a8e885aeeb11b3a3c2 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:42:34 +0100 Subject: [PATCH 07/10] avformat/mov: ignore iacb outside a trak Fixes: codec id change by an iacb outside a trak Fixes: sj3x4TsLBhUY Found during the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25671 --- libavformat/mov.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 0c2f592e7f3..0c5ded3f006 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -928,12 +928,13 @@ static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom) int nb_frames, disposition; int version, ret; + st = get_curr_st(c); + if (!st) + return 0; + if (atom.size < 5) return AVERROR_INVALIDDATA; - if (c->fc->nb_streams < 1) - return 0; - version = avio_r8(pb); if (version != 1) { av_log(c->fc, AV_LOG_ERROR, "%s configurationVersion %d", @@ -945,7 +946,6 @@ static int mov_read_iacb(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!descriptors_size || descriptors_size > INT_MAX) return AVERROR_INVALIDDATA; - st = c->fc->streams[c->fc->nb_streams - 1]; sc = st->priv_data; if (st->codecpar->extradata) { -- 2.54.0 >From cd9665deac784293ad7677250021f2b5a6c6ba78 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:00:32 +0100 Subject: [PATCH 08/10] avformat/mov: do not copy an empty index to the IAMF substreams Fixes: null pointer passed as argument 2, which is declared to never be null Fixes: DPPYwrys5OTb Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25671 Null pointer argument Replicated through UnModified FFmpeg with UBSAN --- libavformat/mov.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 0c5ded3f006..a3abe65692a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -5561,7 +5561,8 @@ static int mov_update_iamf_streams(MOVContext *c, const AVStream *st) out_sti->index_entries_allocated_size = sti->index_entries_allocated_size; out_sti->nb_index_entries = sti->nb_index_entries; out_sti->skip_samples = sti->skip_samples; - memcpy(out_sti->index_entries, sti->index_entries, sti->index_entries_allocated_size); + if (sti->index_entries_allocated_size) + memcpy(out_sti->index_entries, sti->index_entries, sti->index_entries_allocated_size); } } -- 2.54.0 >From c0b0173b0f1820c78f06938063698d10433fcf8a Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:55:16 +0100 Subject: [PATCH 09/10] fftools/ffmpeg_filter: do not use a fallback frame that was not allocated Fixes: NULL pointer dereference Fixes: avif/gain_map_alpha_grid.avif without an AV1 software decoder Fixes: fsm1bknlI5TP Found-by: Onur Tirtir <[email protected]> The crash is mentioned in https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25917 This is not a security issue. NULL pointer dereference Replicated through UnModified FFmpeg --- fftools/ffmpeg_filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 32ff6648555..6b84617b5bf 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -3181,7 +3181,7 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, if (ret < 0) return ret; } else { - if (ifp->format < 0) { + if (ifp->format < 0 && ifp->opts.fallback) { // the filtergraph was never configured, use the fallback parameters ifp->format = ifp->opts.fallback->format; ifp->sample_rate = ifp->opts.fallback->sample_rate; -- 2.54.0 >From c88645fa3ce9abddf3edd1b03cc3e298d4de59d0 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Wed, 11 Nov 2026 17:45:44 +0100 Subject: [PATCH 10/10] fftools/ffmpeg_filter: mark the frame sent for an output without frames as EOF When the output feeds another filtergraph, that filtergraph expects FRAME_OPAQUE_EOF on a frame without buffers. Fixes: Assertion o == FRAME_OPAQUE_EOF failed Fixes: avif/gain_map_alpha_grid.avif without an AV1 software decoder Fixes: fsm1bknlI5TP Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25671 Assertion failure Replicated through UnModified FFmpeg --- fftools/ffmpeg_filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 6b84617b5bf..e377dac45f6 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -2821,6 +2821,7 @@ static int close_output(OutputFilterPriv *ofp, FilterGraphThread *fgt) fd->frame_rate_filter = ofp->fps.framerate; av_assert0(!frame->buf[0]); + frame->opaque = (void*)(intptr_t)FRAME_OPAQUE_EOF; av_log(ofp, AV_LOG_WARNING, "No filtered frames for output stream, trying to " -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
