PR #25795 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795.patch
>From cd772122c3fdf4cc2e75f4a5b0065f9d527a59b5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 01:58:10 +0100 Subject: [PATCH 1/9] avformat/dashdec: limit the number of segments of a SegmentTimeline Fixes: Timeout Fixes: JyLanfEvTbhF Fixes: swarm-Unbounded-timeline-repeat-causes-CPU-DoS-699421 Found-by: zhang xingxing <[email protected]> Timeout Replicated through UnModified FFmpeg (ffprobe) with a timeout Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/dashdec.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c index 00f91fc205a..43cbfa18abc 100644 --- a/libavformat/dashdec.c +++ b/libavformat/dashdec.c @@ -34,6 +34,7 @@ #include "url.h" #define INITIAL_BUFFER_SIZE 32768 +#define MAX_TIMELINE_SEGMENTS (1 << 24) struct fragment { int64_t url_offset; @@ -1125,6 +1126,16 @@ static int parse_manifest_representation(AVFormatContext *s, const char *url, goto free; } + int64_t nb_timeline_segments = 0; + for (int i = 0; i < rep->n_timelines; i++) { + nb_timeline_segments += av_clip64(rep->timelines[i]->repeat, 0, INT_MAX) + 1; + if (nb_timeline_segments > MAX_TIMELINE_SEGMENTS) { + av_log(s, AV_LOG_ERROR, "Too many segments in SegmentTimeline\n"); + ret = AVERROR_INVALIDDATA; + goto free; + } + } + if (rep->fragment_duration > 0 && !rep->fragment_timescale) rep->fragment_timescale = 1; rep->bandwidth = rep_bandwidth_val ? atoi(rep_bandwidth_val) : 0; -- 2.54.0 >From e700279e2e51dcb33a6712bd86e99377af4acbf1 Mon Sep 17 00:00:00 2001 From: zhang xingxing <[email protected]> Date: Fri, 6 Nov 2026 02:00:36 +0100 Subject: [PATCH 2/9] avformat/imf_cpl: reject an EntryPoint beyond the IntrinsicDuration SMPTE ST 2067-3 requires SourceDuration to be between 0 and IntrinsicDuration - EntryPoint. Fixes: signed integer overflow Fixes: SQJJJ0fTnvsv Fixes: swarm-Unsigned-underflow-in-fill_base_resource-EntryPoint-handling-c8cd96 Found-by: zhang xingxing <[email protected]> Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/imf_cpl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/imf_cpl.c b/libavformat/imf_cpl.c index dba502007ce..0edfcbec036 100644 --- a/libavformat/imf_cpl.c +++ b/libavformat/imf_cpl.c @@ -351,6 +351,10 @@ static int fill_base_resource(void *log_ctx, xmlNodePtr resource_elem, av_log(log_ctx, AV_LOG_ERROR, "Invalid IntrinsicDuration element found in a Resource\n"); return ret; } + if (resource->entry_point > resource->duration) { + av_log(log_ctx, AV_LOG_ERROR, "EntryPoint is beyond the IntrinsicDuration of a Resource\n"); + return AVERROR_INVALIDDATA; + } resource->duration -= resource->entry_point; /* read SourceDuration */ -- 2.54.0 >From e6e6f0a544ef011ae34b9ac91b9de74c3da67308 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 02:00:49 +0100 Subject: [PATCH 3/9] avformat/imfdec: compute the resource end time without overflow Fixes: signed integer overflow Fixes: x8FdiC5jwHwL Found-by: zhang xingxing <[email protected]> Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/imfdec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c index 84b7a4d6e3d..39a95366e6c 100644 --- a/libavformat/imfdec.c +++ b/libavformat/imfdec.c @@ -466,6 +466,7 @@ static int open_track_file_resource(AVFormatContext *s, { IMFContext *c = s->priv_data; IMFAssetLocator *asset_locator; + AVRational duration; void *tmp; asset_locator = find_asset_map_locator(&c->asset_locator_map, track_file_resource->track_file_uuid); @@ -493,6 +494,10 @@ static int open_track_file_resource(AVFormatContext *s, return AVERROR(ENOMEM); track->resources = tmp; + av_reduce(&duration.num, &duration.den, + track_file_resource->base.duration * (int64_t)track_file_resource->base.edit_rate.den, + track_file_resource->base.edit_rate.num, INT_MAX); + for (uint32_t i = 0; i < track_file_resource->base.repeat_count; i++) { IMFVirtualTrackResourcePlaybackCtx vt_ctx; @@ -503,10 +508,7 @@ static int open_track_file_resource(AVFormatContext *s, vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time, av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1), track_file_resource->base.edit_rate)); - vt_ctx.end_time = av_add_q(track->duration, - av_make_q((int)track_file_resource->base.duration - * track_file_resource->base.edit_rate.den, - track_file_resource->base.edit_rate.num)); + vt_ctx.end_time = av_add_q(track->duration, duration); track->resources[track->resource_count++] = vt_ctx; track->duration = vt_ctx.end_time; } -- 2.54.0 >From eaea10690f372a714eec7d26d1e574a233be70f1 Mon Sep 17 00:00:00 2001 From: zhang xingxing <[email protected]> Date: Fri, 6 Nov 2026 02:04:07 +0100 Subject: [PATCH 4/9] avformat/bink: reject frames too small for the audio size field Fixes: integer underflow Fixes: x58AlI4Komta Fixes: swarm-Underflow-in-remain_packet_size-check-in-Bink-read_packet-391e16 Found-by: zhang xingxing <[email protected]> Unsigned underflow Replicated through UnModified FFmpeg with ffprobe Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/bink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/bink.c b/libavformat/bink.c index 18eaeba7388..6becc590310 100644 --- a/libavformat/bink.c +++ b/libavformat/bink.c @@ -263,7 +263,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) while (bink->current_track < bink->num_audio_tracks) { uint32_t audio_size = avio_rl32(pb); - if (audio_size > bink->remain_packet_size - 4) { + if (audio_size + 4LL > bink->remain_packet_size) { av_log(s, AV_LOG_ERROR, "frame %"PRId64": audio size in header (%"PRIu32") > size of packet left (%"PRIu32")\n", bink->video_pts, audio_size, bink->remain_packet_size); -- 2.54.0 >From 4c4327f6cb6d198cb01b9768611600e6356b8f87 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 02:05:06 +0100 Subject: [PATCH 5/9] avfilter/vsrc_mandelbrot: skip the inner coloring when no iteration ran This is not a security issue. Fixes: out of array read Fixes: use of uninitialized memory Fixes: LPW4jFrf2FjP Fixes: swarm-Unbounded-OOB-heap-read-in-PERIOD-inner-coloring-when-maxiter-8-74e806 Found-by: zhang xingxing <[email protected]> Out of array read Replicated through UnModified FFmpeg with ASAN Use of uninitialized memory Replicated through UnModified FFmpeg with Valgrind Signed-off-by: Michael Niedermayer <[email protected]> --- libavfilter/vsrc_mandelbrot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vsrc_mandelbrot.c b/libavfilter/vsrc_mandelbrot.c index 3f14f1e7f9f..0d0e28e8fae 100644 --- a/libavfilter/vsrc_mandelbrot.c +++ b/libavfilter/vsrc_mandelbrot.c @@ -345,7 +345,7 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize, break; } } - if(!c){ + if(!c && i){ if(s->inner==PERIOD){ int j; for(j=i-1; j; j--) -- 2.54.0 >From 4532307261c8a521832a07d099ff4a32f380f038 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 02:05:32 +0100 Subject: [PATCH 6/9] avfilter/vsrc_mandelbrot: compute the cycle buffer size without overflow maxiter + 16 overflows int for maxiter close to INT_MAX. Fixes: signed integer overflow Fixes: 6TKPc39mkuWR Found during triage of the security report LPW4jFrf2FjP Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Signed-off-by: Michael Niedermayer <[email protected]> --- libavfilter/vsrc_mandelbrot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vsrc_mandelbrot.c b/libavfilter/vsrc_mandelbrot.c index 0d0e28e8fae..7f9d86b1d61 100644 --- a/libavfilter/vsrc_mandelbrot.c +++ b/libavfilter/vsrc_mandelbrot.c @@ -131,7 +131,7 @@ static av_cold int init(AVFilterContext *ctx) s->cache_used = 0; s->point_cache= av_malloc_array(s->cache_allocated, sizeof(*s->point_cache)); s-> next_cache= av_malloc_array(s->cache_allocated, sizeof(*s-> next_cache)); - s-> zyklus = av_malloc_array(s->maxiter + 16, sizeof(*s->zyklus)); + s-> zyklus = av_malloc_array(s->maxiter + 16LL, sizeof(*s->zyklus)); if (!s->point_cache || !s->next_cache || !s->zyklus) return AVERROR(ENOMEM); -- 2.54.0 >From 717ea7243990851f3d93b0b4456986c7f9cbd9ea Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 02:05:55 +0100 Subject: [PATCH 7/9] avfilter/vsrc_mandelbrot: check the frame size before allocating the point cache Fixes: signed integer overflow Fixes: iT7bvqnOb6Qq Found during triage of the security report LPW4jFrf2FjP Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Signed-off-by: Michael Niedermayer <[email protected]> --- libavfilter/vsrc_mandelbrot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavfilter/vsrc_mandelbrot.c b/libavfilter/vsrc_mandelbrot.c index 7f9d86b1d61..564069e3bda 100644 --- a/libavfilter/vsrc_mandelbrot.c +++ b/libavfilter/vsrc_mandelbrot.c @@ -121,6 +121,10 @@ AVFILTER_DEFINE_CLASS(mandelbrot); static av_cold int init(AVFilterContext *ctx) { MBContext *s = ctx->priv; + int ret = av_image_check_size(s->w, s->h, 0, ctx); + + if (ret < 0) + return ret; s->bailout *= s->bailout; @@ -154,9 +158,6 @@ static int config_props(AVFilterLink *outlink) FilterLink *l = ff_filter_link(outlink); MBContext *s = ctx->priv; - if (av_image_check_size(s->w, s->h, 0, ctx) < 0) - return AVERROR(EINVAL); - outlink->w = s->w; outlink->h = s->h; outlink->time_base = av_inv_q(s->frame_rate); -- 2.54.0 >From 5d8906bce52bac2855254f5a949dfb6943365ca7 Mon Sep 17 00:00:00 2001 From: zhang xingxing <[email protected]> Date: Fri, 6 Nov 2026 02:08:08 +0100 Subject: [PATCH 8/9] avcodec/jpeg2000_parser: fix the tile-part length check This is not a security issue. Fixes: integer underflow Fixes: kgusFCuY3WYo Fixes: swarm-Unsigned-arithmetic-underflow-in-tile-part-skip_bytes-calculation-d23292 Found-by: zhang xingxing <[email protected]> Merged frames Replicated through UnModified FFmpeg with ffprobe Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/jpeg2000_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c index a5dcc9c9f1b..edf47934d57 100644 --- a/libavcodec/jpeg2000_parser.c +++ b/libavcodec/jpeg2000_parser.c @@ -122,7 +122,7 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ } if (m->read_tp) { // Find out how many bytes inside Tile part codestream to skip. if (m->read_tp == 1) { - m->skip_bytes = (state64 & 0xFFFFFFFF) - 9 > 0? + m->skip_bytes = (state64 & 0xFFFFFFFF) > 9 ? (state64 & 0xFFFFFFFF) - 9 : 0; } m->read_tp--; -- 2.54.0 >From e39fe3dd2c6bbfb0562410b1c81f1f9a90c79d08 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Fri, 6 Nov 2026 02:09:33 +0100 Subject: [PATCH 9/9] avcodec/jpeg2000_parser: look only for EOC in the data of a tile-part with Psot 0 Fixes: 9ulyCCXNUqlt Found during triage of the security report kgusFCuY3WYo Merged frames Replicated through UnModified FFmpeg with ffprobe Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/jpeg2000_parser.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libavcodec/jpeg2000_parser.c b/libavcodec/jpeg2000_parser.c index edf47934d57..8a3aac9ef50 100644 --- a/libavcodec/jpeg2000_parser.c +++ b/libavcodec/jpeg2000_parser.c @@ -45,6 +45,7 @@ typedef struct JPEG2000ParserContext { uint8_t skipped_codestream; uint8_t read_tp; uint8_t in_codestream; + uint8_t skip_to_eoc; } JPEG2000ParserContext; static inline void reset_context(JPEG2000ParserContext *m) @@ -60,6 +61,7 @@ static inline void reset_context(JPEG2000ParserContext *m) m->skip_bytes = 0; m->read_tp = 0; m->in_codestream = 0; + m->skip_to_eoc = 0; } /* Returns 1 if marker has any data which can be skipped @@ -128,6 +130,12 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ m->read_tp--; continue; } + if (m->skip_to_eoc) { + if ((state64 & 0xFFFF) == 0xFF91) + m->skip_bytes = 5; + if ((state64 & 0xFFFF) != 0xFFD9) + continue; + } if (m->fheader_read) { if (m->fheader_read == 1) { if (state64 == 0x6A5020200D0A870A) { // JP2 signature box value. @@ -162,9 +170,12 @@ static int find_frame_end(JPEG2000ParserContext *m, const uint8_t *buf, int buf_ return i + 1; // End of frame detected, return frame size. } m->in_codestream = 0; + m->skip_to_eoc = 0; } else if (m->in_codestream) { if ((state64 & 0xFFFF) == 0xFF90) { // Are we in tile part header? m->read_tp = 8; + } else if ((state64 & 0xFFFF) == 0xFF93) { + m->skip_to_eoc = 1; } else if (info_marker((state64 & 0xFFFF0000)>>16) && pc->frame_start_found && (state64 & 0xFFFF)) { // Calculate number of bytes to skip to get to end of the next marker. m->skip_bytes = (state64 & 0xFFFF)-1; -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
