@@ -16,6 +16,8 @@ use crate::macros::decode_err;
16
16
17
17
use std:: io:: { Read , Seek } ;
18
18
19
+ const SUPPORTED_DOC_TYPES : & [ & str ] = & [ "matroska" , "webm" ] ;
20
+
19
21
pub ( super ) fn read_from < R > ( reader : & mut R , parse_options : ParseOptions ) -> Result < EbmlFile >
20
22
where
21
23
R : Read + Seek ,
@@ -114,6 +116,18 @@ where
114
116
continue ;
115
117
}
116
118
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
+
117
131
// Anything else in the header is unnecessary, and only read for the properties
118
132
// struct
119
133
if !parse_options. read_properties {
@@ -128,9 +142,6 @@ where
128
142
ElementIdent :: EBMLReadVersion => {
129
143
properties. header . read_version = child_reader. read_unsigned_int ( size. value ( ) ) ?
130
144
} ,
131
- ElementIdent :: DocType => {
132
- properties. header . doc_type = child_reader. read_string ( size. value ( ) ) ?
133
- } ,
134
145
ElementIdent :: DocTypeVersion => {
135
146
properties. header . doc_type_version = child_reader. read_unsigned_int ( size. value ( ) ) ?
136
147
} ,
@@ -142,5 +153,10 @@ where
142
153
child_reader. master_exhausted( ) ,
143
154
"There should be no remaining elements in the header"
144
155
) ;
156
+
157
+ if properties. header . doc_type . is_empty ( ) {
158
+ decode_err ! ( @BAIL Ebml , "Unable to determine EBML DocType" ) ;
159
+ }
160
+
145
161
Ok ( ( ) )
146
162
}
0 commit comments