Skip to content

Commit 4e5795f

Browse files
committed
mkv: detect parent overrun after the header parsing
1 parent 2c42c7a commit 4e5795f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

symphonia-format-mkv/src/ebml.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,16 @@ impl<R: ReadEbml, S: EbmlSchema> EbmlIterator<R, S> {
544544
return Err(EbmlError::UnexpectedElement);
545545
}
546546

547-
// It is invalid for a child element's end position to exceed its parent's end position.
548-
// The element may be discarded in such cases.
547+
// perform checks after the header parsing
549548
if let Some(parent_end) = parent_end {
549+
// The parent element was overrun. This can happen during header parsing
550+
if self.reader.pos() > parent_end {
551+
log::warn!("overran parent element by {} bytes", self.reader.pos() - parent_end);
552+
return Err(EbmlError::Overrun);
553+
}
554+
555+
// It is invalid for a child element's end position to exceed its parent's end position.
556+
// The element may be discarded in such cases.
550557
if let Some(child_end) = header.end() {
551558
if child_end > parent_end {
552559
// TODO: Maybe scan for other elements instead of skipping to the end of the

0 commit comments

Comments
 (0)