Skip to content

Commit 11f7728

Browse files
committed
EBML: Restrict parser to certain DocTypes
1 parent c9e3d97 commit 11f7728

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lofty/src/ebml/read.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use crate::macros::decode_err;
1616

1717
use std::io::{Read, Seek};
1818

19+
const SUPPORTED_DOC_TYPES: &[&str] = &["matroska", "webm"];
20+
1921
pub(super) fn read_from<R>(reader: &mut R, parse_options: ParseOptions) -> Result<EbmlFile>
2022
where
2123
R: Read + Seek,
@@ -114,6 +116,18 @@ where
114116
continue;
115117
}
116118

119+
if ident == ElementIdent::DocType {
120+
properties.header.doc_type = child_reader.read_string(size.value())?;
121+
if !SUPPORTED_DOC_TYPES.contains(&properties.header.doc_type.as_str()) {
122+
decode_err!(
123+
@BAIL Ebml,
124+
"Unsupported EBML DocType"
125+
);
126+
}
127+
128+
continue;
129+
}
130+
117131
// Anything else in the header is unnecessary, and only read for the properties
118132
// struct
119133
if !parse_options.read_properties {
@@ -128,9 +142,6 @@ where
128142
ElementIdent::EBMLReadVersion => {
129143
properties.header.read_version = child_reader.read_unsigned_int(size.value())?
130144
},
131-
ElementIdent::DocType => {
132-
properties.header.doc_type = child_reader.read_string(size.value())?
133-
},
134145
ElementIdent::DocTypeVersion => {
135146
properties.header.doc_type_version = child_reader.read_unsigned_int(size.value())?
136147
},
@@ -142,5 +153,10 @@ where
142153
child_reader.master_exhausted(),
143154
"There should be no remaining elements in the header"
144155
);
156+
157+
if properties.header.doc_type.is_empty() {
158+
decode_err!(@BAIL Ebml, "Unable to determine EBML DocType");
159+
}
160+
145161
Ok(())
146162
}

0 commit comments

Comments
 (0)