From 92f9ec98471a131a43bcbe4a64031138b6b67880 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 18 May 2019 12:37:43 +0200 Subject: [PATCH] Matroska reader: don't buffer if reading next frame is forced With very large video frames (one test file has h.264 from Blu-rays with ten seconds between key frames and an average frame size of ~350 KB) buffering due to external timestamps being applied could easily lead to the packetizer holding more than 128 MB of data in memory while waiting for the next key frame before it can apply the timestamps. The reader must not refuse to deliver frames in such a case, otherwise the next I frame will never appear, the packetizer will never write out those buffered frames and the whole process ends up in an endless loop. Fixes #2550. --- NEWS.md | 3 +++ src/input/r_matroska.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e597892b7..a3ea18f06 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,9 @@ wrong data in source files. Fixes #2541. * mkvmerge: AV1: fixed frame timestamp calculation when reading bitstreams that lack timing information from IVF files. Fixes #2553. +* mkvmerge: Matroska reader: fixed an infinite loop that could happen with + large video frames and applied timestamp files due to too much data being + buffered at the wrong time. Fixes #2550. # Version 33.1.0 "Primrose" 2019-04-15 diff --git a/src/input/r_matroska.cpp b/src/input/r_matroska.cpp index 2a89ae897..bb4b77650 100644 --- a/src/input/r_matroska.cpp +++ b/src/input/r_matroska.cpp @@ -2272,7 +2272,7 @@ kax_reader_c::read(generic_packetizer_c *requested_ptzr, auto requested_ptzr_track = m_ptzr_to_track_map[requested_ptzr]; if ( !requested_ptzr_track || (!force && ('a' != requested_ptzr_track->type) && ('v' != requested_ptzr_track->type)) - || (128 * 1024 * 1024 < num_queued_bytes)) + || (!force && (128 * 1024 * 1024 < num_queued_bytes))) return FILE_STATUS_HOLDING; }