PR #26138 opened by michaelni URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26138 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26138.patch
>From 1404aaf5b623d610fd15098d7de14ff515dc6c00 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 1/9] avcodec/sanm: add the FTCH offsets without signed overflow Signed integer overflow Replicated through API with UBSAN Fixes: signed integer overflow: -1 + -2147483648 cannot be represented in type 'int' Fixes: 575276971/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SANM_fuzzer-6288493593296896 Fixes: 04GaICgAPs9q Regression since: b418da28bf3fcd9a80383b0f39e3cd71e55022c1 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/sanm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index dca5e7a..7738cf4 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -2124,8 +2124,8 @@ static int process_frame_obj(SANMVideoContext *ctx, GetByteContext *gb, memset(ctx->fbuf, 0, ctx->frm0_size); } - left += xoff; - top += yoff; + left += (unsigned)xoff; + top += (unsigned)yoff; switch (codec) { case 1: -- 2.54.0 >From 72de023b01809cc7342056def45aff95157c80e5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 2/9] avformat/rpl: check the audio size of a chunk before using it Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Fixes: signed integer overflow: 4133067176707077211 * 8 cannot be represented in type 'int64_t' (aka 'long') Fixes: 578084947/clusterfuzz-testcase-minimized-ffmpeg_dem_RPL_fuzzer-6427797955608576 Fixes: dqnVagTmi5NZ Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/rpl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/rpl.c b/libavformat/rpl.c index 06e3f35..d3aa257 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -301,14 +301,14 @@ static int rpl_read_header(AVFormatContext *s) error = -1; continue; } + if (total_audio_size/8 + (uint64_t)audio_size >= INT64_MAX/8) + return AVERROR_INVALIDDATA; if (vst) av_add_index_entry(vst, offset, i * rpl->frames_per_chunk, video_size, rpl->frames_per_chunk, 0); if (ast) av_add_index_entry(ast, offset + video_size, total_audio_size, audio_size, audio_size * 8, 0); - if (total_audio_size/8 + (uint64_t)audio_size >= INT64_MAX/8) - return AVERROR_INVALIDDATA; total_audio_size += audio_size * 8; } -- 2.54.0 >From 39d73183c3f4afb8654606977fd5fa043ca12b7f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 3/9] avformat/rpl: reject chunks whose video data ends beyond INT64_MAX Chunks with a negative video size are rejected too. Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Found during triage of the OSS-Fuzz issue 578084947 Fixes: signed integer overflow: 9223372036854775807 + 8 cannot be represented in type 'int64_t' (aka 'long') Fixes: oYqfrDQlip85/rpl-offset-overflow.rpl Fixes: oYqfrDQlip85 Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/rpl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/rpl.c b/libavformat/rpl.c index d3aa257..0b3cd07 100644 --- a/libavformat/rpl.c +++ b/libavformat/rpl.c @@ -301,7 +301,8 @@ static int rpl_read_header(AVFormatContext *s) error = -1; continue; } - if (total_audio_size/8 + (uint64_t)audio_size >= INT64_MAX/8) + if (video_size < 0 || offset > INT64_MAX - video_size || + total_audio_size/8 + (uint64_t)audio_size >= INT64_MAX/8) return AVERROR_INVALIDDATA; if (vst) av_add_index_entry(vst, offset, i * rpl->frames_per_chunk, -- 2.54.0 >From 8507cd960078bb4c4160a1579084878fa371b997 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 4/9] avformat/flvdec: apply the concatenation time offset once per tag Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Fixes: signed integer overflow: -9223372032574423263 + -9223372036854775807 cannot be represented in type 'int64_t' (aka 'long') Fixes: 575044121/clusterfuzz-testcase-minimized-ffmpeg_dem_LIVE_FLV_fuzzer-4798271142035456 Fixes: KrOP5n0Tchcx Regression since: e2a8ece352bf72bb05be8e152b1706509706b62a Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/flvdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 29bd7d6..1e52971 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -1564,6 +1564,10 @@ skip: goto leave; } + if (flv->time_pos <= pos) { + dts += flv->time_offset; + } + for (;;) { int track_size = size; if (size < 0) { @@ -1605,10 +1609,6 @@ skip: } av_log(s, AV_LOG_TRACE, "%d %X %d \n", stream_type, flags, st->discard); - if (flv->time_pos <= pos) { - dts += flv->time_offset; - } - if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || stream_type == FLV_STREAM_TYPE_AUDIO)) -- 2.54.0 >From 767ff48c51062b9b0c7aadeb45528163193140c5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 5/9] avformat/matroskadec: reject cue positions before the segment in the DASH manifest Signed integer overflow Replicated through API with UBSAN Fixes: signed integer overflow: 8872126588269895935 - -360550420148060339 cannot be represented in type 'int64_t' (aka 'long') Fixes: 575074290/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6200621636845568 Fixes: a62kXgcPEXgR Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/matroskadec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 0963962..b10bf3a 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -4617,6 +4617,7 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) AVIndexEntry *const index_entries = sti->index_entries; int nb_index_entries = sti->nb_index_entries; CueDesc cue_desc; + int64_t end_pos; int i; if (ts >= (int64_t)(matroska->duration * matroska->time_scale)) @@ -4630,6 +4631,9 @@ static CueDesc get_cue_desc(AVFormatContext *s, int64_t ts, int64_t cues_start) --i; if (index_entries[i].timestamp > matroska->duration) return (CueDesc) {-1, -1, -1, -1}; + end_pos = i != nb_index_entries - 1 ? index_entries[i + 1].pos : cues_start; + if (index_entries[i].pos < matroska->segment_start || end_pos < matroska->segment_start) + return (CueDesc) {-1, -1, -1, -1}; cue_desc.start_time_ns = index_entries[i].timestamp * matroska->time_scale; cue_desc.start_offset = index_entries[i].pos - matroska->segment_start; if (i != nb_index_entries - 1) { -- 2.54.0 >From 7ee73d2038ffb4d621b62b421b1d8781177ce21b Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 6/9] avcodec/proresdsp: avoid signed overflow in the ProRes RAW dequantization Signed integer overflow Replicated through API with UBSAN Fixes: signed integer overflow: -154665 * 16575 cannot be represented in type 'int' Fixes: 572632128/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_PRORES_RAW_DEC_fuzzer-6177287729643520 Fixes: T1p6OXTgBhLz Regression since: bc1cf21643f6cb63c0756268f61bf33ebd0b8712 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavcodec/proresdsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/proresdsp.c b/libavcodec/proresdsp.c index 919a5d6..9a5cba5 100644 --- a/libavcodec/proresdsp.c +++ b/libavcodec/proresdsp.c @@ -88,7 +88,7 @@ static void prores_idct_12(int16_t *restrict block, const int16_t *restrict qmat static void prores_idct_bayer_16(int32_t *restrict block, const int16_t *restrict qmat) { for (int i = 0; i < 64; i++) - block[i] = av_clip_int16(block[i] * qmat[i]); + block[i] = av_clip_int16(block[i] * (unsigned)qmat[i]); for (int i = 0; i < 8; i++) idctRowCondDC_int32_16bit(block + i*8, 0); -- 2.54.0 >From 5c9bb8a8a3be4f2ea6a11b374987c4da57711550 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:38 +0100 Subject: [PATCH 7/9] swscale/output: avoid signed overflow in the chroma products of yuv2gbrp16_full_X_c() Signed integer overflow Replicated through API with UBSAN Fixes: signed integer overflow: -130356 * 16525 cannot be represented in type 'int' Fixes: 574937224/clusterfuzz-testcase-minimized-ffmpeg_SWS_fuzzer-5275640446910464 Fixes: RSXytemqmJPo Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libswscale/output.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 3e9086a..463de1d 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -2522,9 +2522,9 @@ yuv2gbrp16_full_X_c(SwsInternal *c, const int16_t *lumFilter, Y -= c->yuv2rgb_y_offset; Y *= c->yuv2rgb_y_coeff; Y += (1 << 13) - (1 << 29); - R = V * c->yuv2rgb_v2r_coeff; - G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; - B = U * c->yuv2rgb_u2b_coeff; + R = V * (unsigned)c->yuv2rgb_v2r_coeff; + G = V * (unsigned)c->yuv2rgb_v2g_coeff + U * (unsigned)c->yuv2rgb_u2g_coeff; + B = U * (unsigned)c->yuv2rgb_u2b_coeff; dest16[2][i] = av_clip_uintp2(((Y + (int64_t)R) >> 14) + (1<<15), 16); dest16[0][i] = av_clip_uintp2(((Y + (int64_t)G) >> 14) + (1<<15), 16); -- 2.54.0 >From 895185fa06bde101613f6ec19d96dff70a71b34d Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:47 +0100 Subject: [PATCH 8/9] swscale/output: avoid signed overflow in yuv2gbrpf32_full_X_c() The chroma products and the sums are computed like in yuv2gbrp16_full_X_c() Found during review of the fix for the OSS-Fuzz issue 574937224 Signed-off-by: Michael Niedermayer <[email protected]> --- libswscale/output.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libswscale/output.c b/libswscale/output.c index 463de1d..cf3cea8 100644 --- a/libswscale/output.c +++ b/libswscale/output.c @@ -2595,13 +2595,13 @@ yuv2gbrpf32_full_X_c(SwsInternal *c, const int16_t *lumFilter, Y -= c->yuv2rgb_y_offset; Y *= c->yuv2rgb_y_coeff; Y += (1 << 13) - (1 << 29); - R = V * c->yuv2rgb_v2r_coeff; - G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; - B = U * c->yuv2rgb_u2b_coeff; + R = V * (unsigned)c->yuv2rgb_v2r_coeff; + G = V * (unsigned)c->yuv2rgb_v2g_coeff + U * (unsigned)c->yuv2rgb_u2g_coeff; + B = U * (unsigned)c->yuv2rgb_u2b_coeff; - R = av_clip_uintp2(((Y + R) >> 14) + (1<<15), 16); - G = av_clip_uintp2(((Y + G) >> 14) + (1<<15), 16); - B = av_clip_uintp2(((Y + B) >> 14) + (1<<15), 16); + R = av_clip_uintp2(((Y + (int64_t)R) >> 14) + (1<<15), 16); + G = av_clip_uintp2(((Y + (int64_t)G) >> 14) + (1<<15), 16); + B = av_clip_uintp2(((Y + (int64_t)B) >> 14) + (1<<15), 16); dest32[0][i] = av_float2int(float_mult * (float)G); dest32[1][i] = av_float2int(float_mult * (float)B); -- 2.54.0 >From 3e6458977a17d28efb156fa64550a30b55f440f5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Mon, 16 Nov 2026 06:56:47 +0100 Subject: [PATCH 9/9] avformat/demux: saturate the end sample used for the discard padding Signed integer overflow Replicated through UnModified FFmpeg with UBSAN Fixes: signed integer overflow: 8479735170118198272 + 942192796679799808 cannot be represented in type 'int64_t' (aka 'long') Fixes: 584661914/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-5041842006327296 Fixes: FgJWeOCmmFCb Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <[email protected]> --- libavformat/demux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 3c5157d..1eea4c1 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1561,7 +1561,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0); int64_t sample = ts_to_samples(st, pts); int64_t duration = FFMAX(st->codecpar->frame_size, ts_to_samples(st, pkt->duration)); - int64_t end_sample = sample + duration; + int64_t end_sample = av_sat_add64(sample, duration); if (duration > 0 && end_sample >= sti->first_discard_sample && sample < sti->last_discard_sample) discard_padding = FFMIN(end_sample - sti->first_discard_sample, duration); -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
