Skip to content

Commit 9463c48

Browse files
committed
MP4: Check for unexpected atoms sooner
1 parent 5688cdd commit 9463c48

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

lofty/src/mp4/ilst/read.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ where
236236
break;
237237
}
238238

239+
if next_atom.ident != DATA_ATOM_IDENT {
240+
if parsing_mode == ParsingMode::Strict {
241+
err!(BadAtom("Expected atom \"data\" to follow name"))
242+
}
243+
244+
log::warn!(
245+
"Skipping unexpected atom {actual_ident:?}, expected {expected_ident:?}",
246+
actual_ident = next_atom.ident,
247+
expected_ident = DATA_ATOM_IDENT
248+
);
249+
250+
pos += next_atom.len;
251+
skip_unneeded(reader, next_atom.extended, next_atom.len)?;
252+
continue;
253+
}
254+
239255
let Some(data_type) = parse_type_indicator(reader, parsing_mode)? else {
240256
log::warn!("Skipping atom with unknown type set");
241257
let remaining_atom_len = next_atom.len - (ATOM_HEADER_LEN + 1);
@@ -248,31 +264,13 @@ where
248264
// We don't care about the locale
249265
reader.seek(SeekFrom::Current(4))?;
250266

251-
match next_atom.ident {
252-
DATA_ATOM_IDENT => {
253-
let content_len = (next_atom.len - 16) as usize;
254-
if content_len > 0 {
255-
let mut content = try_vec![0; content_len];
256-
reader.read_exact(&mut content)?;
257-
ret.push((data_type, content));
258-
} else {
259-
log::warn!("Skipping empty \"data\" atom");
260-
}
261-
},
262-
_ => match parsing_mode {
263-
ParsingMode::Strict => {
264-
err!(BadAtom("Expected atom \"data\" to follow name"))
265-
},
266-
ParsingMode::BestAttempt | ParsingMode::Relaxed => {
267-
log::warn!(
268-
"Skipping unexpected atom {actual_ident:?}, expected {expected_ident:?}",
269-
actual_ident = next_atom.ident,
270-
expected_ident = DATA_ATOM_IDENT
271-
);
272-
273-
reader.seek(SeekFrom::Current((next_atom.len - 16) as i64))?;
274-
},
275-
},
267+
let content_len = (next_atom.len - 16) as usize;
268+
if content_len > 0 {
269+
let mut content = try_vec![0; content_len];
270+
reader.read_exact(&mut content)?;
271+
ret.push((data_type, content));
272+
} else {
273+
log::warn!("Skipping empty \"data\" atom");
276274
}
277275

278276
pos += next_atom.len;

0 commit comments

Comments
 (0)