Commit 342cb6374f for ffmpeg

commit 342cb6374fee2e7a86b35235203e3eefc9572969
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Mon Nov 16 06:56:47 2026 +0100

    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 <michael@niedermayer.cc>

diff --git a/libavformat/demux.c b/libavformat/demux.c
index 3c5157df4e..1eea4c16d9 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);