From 4aaac5d65e6bf8b412d1295c7d3439aa86632ced Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 30 Apr 2026 16:28:00 +0200 Subject: [PATCH] EbmlMaster: exit reading loop if upper element found ends after its parent It could be a file with missing data in the middle. And we shouldn't use a MaxSizeToRead that would be negative. --- src/EbmlMaster.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index 5f210ff0..d91ab06e 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -470,6 +470,9 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo } ElementLevelA = FoundElt; if (IsFiniteSize() && ElementLevelA->IsFiniteSize()) { + if (ElementLevelA->GetEndPosition() > GetEndPosition()) { + goto processCrc; // found an upper element that ends after this, we were truncated + } MaxSizeToRead = GetEndPosition() - ElementLevelA->GetEndPosition(); // even if it's the default value } continue;