Skip to content

Commit

Permalink
mkv: detect parent overrun after the header parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sscobici committed Jan 17, 2025
1 parent df505ea commit 0d10b52
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions symphonia-format-mkv/src/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,16 @@ impl<R: ReadEbml, S: EbmlSchema> EbmlIterator<R, S> {
return Err(EbmlError::UnexpectedElement);
}

// It is invalid for a child element's end position to exceed its parent's end position.
// The element may be discarded in such cases.
// perform checks after the header parsing
if let Some(parent_end) = parent_end {
// The parent element was overrun. This can happen during header parsing
if self.reader.pos() > parent_end {
log::warn!("overran parent element by {} bytes", self.reader.pos() - parent_end);
return Err(EbmlError::Overrun);
}

// It is invalid for a child element's end position to exceed its parent's end position.
// The element may be discarded in such cases.
if let Some(child_end) = header.end() {
if child_end > parent_end {
// TODO: Maybe scan for other elements instead of skipping to the end of the
Expand Down

0 comments on commit 0d10b52

Please sign in to comment.