PR #24839 opened by MMu-Aqua
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24839
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24839.patch

Fixes Issue #24831.

ts_discontinuity_detect() uses FFABS(delta) on an int64_t timestamp delta.
When delta == INT64_MIN, that negation is undefined. On the attached PoC the 
next statement ts_offset_discont -= delta is then 0 - INT64_MIN, which is the 
same class of signed overflow.

Use FFABS64U() for the comparison and unsigned wrap for the offset update, only 
on the branch hit by the PoC.

The fix was reproduced with the PoC attached to Issue #24831.

Fixes: #24831


>From 98eb86407e0de42330e0600efb956f4dd3b60bcf Mon Sep 17 00:00:00 2001
From: MMu-Aqua <[email protected]>
Date: Thu, 1 Oct 2026 02:30:25 -0700
Subject: [PATCH] fftools/ffmpeg_demux: avoid undefined FFABS() on INT64_MIN

FFABS() negates its argument, which is undefined for INT64_MIN.
On the PoC path the following ts_offset_discont -= delta is then
0 - INT64_MIN. Use FFABS64U() and unsigned wrap for that branch.

Fixes: #24831
Signed-off-by: MMu-Aqua <[email protected]>
---
 fftools/ffmpeg_demux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 8ae5486582..d4294e94a8 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -293,8 +293,8 @@ static void ts_discontinuity_detect(Demuxer *d, InputStream 
*ist,
     } else if (ds->next_dts == AV_NOPTS_VALUE && !copy_ts &&
                fmt_is_discont && d->last_ts != AV_NOPTS_VALUE) {
         int64_t delta = pkt_dts - d->last_ts;
-        if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
-            d->ts_offset_discont -= delta;
+        if (FFABS64U(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
+            d->ts_offset_discont = (int64_t)((uint64_t)d->ts_offset_discont - 
(uint64_t)delta);
             av_log(ist, AV_LOG_DEBUG,
                    "Inter stream timestamp discontinuity %"PRId64", new 
offset= %"PRId64"\n",
                    delta, d->ts_offset_discont);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to