PR #25050 opened by Marvin Scholz (ePirat)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25050
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25050.patch

Reset `matroska->duration` to 0 if it is negative or if `matroska->duration *
matroska->time_scale` would exceed `INT64_MAX`, preventing a float-cast-overflow
when calculating the duration.


>From 6f8c6cc5d6ebeb861be6c0c48bf062b8adff4fa7 Mon Sep 17 00:00:00 2001
From: Marvin Scholz <[email protected]>
Date: Tue, 29 Sep 2026 13:00:40 +0000
Subject: [PATCH] avformat/matroskadec: prevent duration float-cast-overflow

Reset matroska->duration to 0 if it is negative or if matroska->duration *
matroska->time_scale would exceed INT64_MAX, preventing a float-cast-overflow
when calculating the duration.

Signed-off-by: Marvin Scholz <[email protected]>
---
 libavformat/matroskadec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index bceb4f7e17..109a82a56b 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3506,7 +3506,8 @@ static int matroska_read_header(AVFormatContext *s)
 
     if (!matroska->time_scale)
         matroska->time_scale = 1000000;
-    if (isnan(matroska->duration))
+    if (isnan(matroska->duration) || matroska->duration < 0 ||
+        matroska->duration >= (double)INT64_MAX / matroska->time_scale)
         matroska->duration = 0;
     if (matroska->duration)
         matroska->ctx->duration = matroska->duration * matroska->time_scale *
-- 
2.52.0

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

Reply via email to