swf: Fix uncompressed length check

This commit is contained in:
Mike Welsh 2021-01-19 20:00:58 -08:00
parent c063264d1c
commit 303a2620a7
2 changed files with 12 additions and 8 deletions

View File

@ -79,21 +79,23 @@ pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result<SwfBuf> {
}
};
// Decompress the entire SWF.
let mut data = Vec::with_capacity(uncompressed_length as usize);
if let Err(e) = decompress_stream.read_to_end(&mut data) {
log::error!("Error decompressing SWF: {}", e);
}
// Some SWF streams may not be compressed correctly,
// (e.g. incorrect data length in the stream), so decompressing
// may throw an error even though the data otherwise comes
// through the stream.
// We'll still try to parse what we get if the full decompression fails.
let mut decompressed_input = Vec::with_capacity(uncompressed_length as usize);
if let Err(e) = decompress_stream.read_to_end(&mut decompressed_input) {
log::error!("Error decompressing SWF: {}", e);
}
if decompressed_input.len() as u64 != uncompressed_length as u64 {
// (+ 8 for header size)
if data.len() as u64 + 8 != uncompressed_length as u64 {
log::warn!("SWF length doesn't match header, may be corrupt");
}
let mut reader = Reader::new(&decompressed_input, version);
let mut reader = Reader::new(&data, version);
let stage_size = reader.read_rectangle()?;
let frame_rate = reader.read_fixed8()?;
let num_frames = reader.read_u16()?;

View File

@ -22,8 +22,10 @@ pub struct Swf<'a> {
/// Returned by `read::decompress_swf`.
/// Owns the decompressed SWF data, which will be referenced when parsed by `parse_swf`.
pub struct SwfBuf {
/// The parsed SWF header.
pub header: Header,
//pub reader: crate::read::Reader<'a>,
/// The decompressed SWF tag stream.
pub data: Vec<u8>,
}