PR #20653 opened by James Almer (jamrial)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20653
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20653.patch

There seem to be samples with no Video element on video tracks in the wild, 
which even if not spec compliant, can be demuxed fine after lavf probes the 
stream with a decoder/parser.
Relax the check to allow tracks with no dimensions to work, and also add a 
check for strict spec compliance to maintain the current behavior if desired.

Fixes issue #20649.


>From 0de01622dd901e78a1d6a4faef0f18afba537667 Mon Sep 17 00:00:00 2001
From: James Almer <[email protected]>
Date: Mon, 6 Oct 2025 10:21:03 -0300
Subject: [PATCH] avformat/matroskadec: relax the check for cropped dimensions

There seem to be samples with no Video element on video tracks in the wild,
which even if not spec compliant, can be demuxed fine after lavf probes the
stream with a decoder/parser.
Relax the check to allow tracks with no dimensions to work, and also add a
check for strict spec compliance to maintain the current behavior if desired.

Fixes issue #20649.

Signed-off-by: James Almer <[email protected]>
---
 libavformat/matroskadec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6c12e1594c..c4190cc059 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -3168,10 +3168,13 @@ static int matroska_parse_tracks(AVFormatContext *s)
                     track->default_duration = default_duration;
                 }
             }
+            if (matroska->ctx->strict_std_compliance >= FF_COMPLIANCE_STRICT &&
+                (!track->video.pixel_width || !track->video.pixel_height))
+                return AVERROR_INVALIDDATA;
             if (track->video.pixel_cropl >= INT_MAX - track->video.pixel_cropr 
||
                 track->video.pixel_cropt >= INT_MAX - track->video.pixel_cropb 
||
-                (track->video.pixel_cropl + track->video.pixel_cropr) >= 
track->video.pixel_width ||
-                (track->video.pixel_cropt + track->video.pixel_cropb) >= 
track->video.pixel_height)
+                (track->video.pixel_cropl + track->video.pixel_cropr) >= 
track->video.pixel_width + !track->video.pixel_width ||
+                (track->video.pixel_cropt + track->video.pixel_cropb) >= 
track->video.pixel_height + !track->video.pixel_height)
                 return AVERROR_INVALIDDATA;
             track->video.cropped_width  = track->video.pixel_width  -
                                           track->video.pixel_cropl  - 
track->video.pixel_cropr;
-- 
2.49.1

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

Reply via email to