1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00

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 <jamrial@gmail.com>
This commit is contained in:
James Almer
2025-10-06 10:21:03 -03:00
parent ccb1865a82
commit e10473f13e

View File

@@ -3168,11 +3168,20 @@ static int matroska_parse_tracks(AVFormatContext *s)
track->default_duration = default_duration;
}
}
if (track->video.pixel_cropl >= INT_MAX - track->video.pixel_cropr ||
int has_dimensions = track->video.pixel_width || track->video.pixel_height;
if ((matroska->ctx->strict_std_compliance >= FF_COMPLIANCE_STRICT &&
(!track->video.pixel_width || !track->video.pixel_height)) ||
(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 + !has_dimensions ||
(track->video.pixel_cropt + track->video.pixel_cropb) >= track->video.pixel_height + !has_dimensions)) {
av_log(matroska->ctx, AV_LOG_ERROR,
"Invalid coded dimensions %"PRId64"x%"PRId64" [%"PRId64", %"PRId64", %"PRId64", %"PRId64"].\n",
track->video.pixel_width, track->video.pixel_height,
track->video.pixel_cropl, track->video.pixel_cropr,
track->video.pixel_cropt, track->video.pixel_cropb);
return AVERROR_INVALIDDATA;
}
track->video.cropped_width = track->video.pixel_width -
track->video.pixel_cropl - track->video.pixel_cropr;
track->video.cropped_height = track->video.pixel_height -