diff --git a/swf/src/read.rs b/swf/src/read.rs index 9f8e14670..adb3aaae4 100644 --- a/swf/src/read.rs +++ b/swf/src/read.rs @@ -657,10 +657,20 @@ impl Reader { } }; - if cfg!(debug_assertions) && tag_reader.read_u8().is_ok() { + if tag_reader.read_u8().is_ok() { // There should be no data remaining in the tag if we read it correctly. - // If there is data remaining, we probably screwed up, so panic in debug builds. - panic!("Error reading tag {:?}", tag_code); + // If there is data remaining, the most likely scenario is we screwed up parsing. + // But sometimes tools will export SWF tags that are larger than they should be. + // TODO: It might be worthwhile to have a "strict mode" to determine + // whether this should error or not. + log::warn!( + "Data remaining in buffer when parsing {} ({})", + TagCode::name(tag_code), + tag_code + ); + + // Discard the rest of the data. + let _ = std::io::copy(&mut tag_reader.get_mut(), &mut io::sink()); } Ok(tag) diff --git a/swf/src/tag_code.rs b/swf/src/tag_code.rs index 3e0017b0a..d1a3ed8af 100644 --- a/swf/src/tag_code.rs +++ b/swf/src/tag_code.rs @@ -95,4 +95,12 @@ impl TagCode { pub fn from_u16(n: u16) -> Option { num_traits::FromPrimitive::from_u16(n) } + + pub fn name(n: u16) -> String { + if let Some(n) = TagCode::from_u16(n) { + format!("{:?}", n) + } else { + format!("Unknown({})", n) + } + } }