From 2a01260f524b0210c017b87d905d294c81ce3cca Mon Sep 17 00:00:00 2001 From: David Wendt Date: Sat, 20 Mar 2021 22:33:31 -0400 Subject: [PATCH] avm2: `bytesLoaded` etc reports the compressed file length, not the uncompressed length --- core/src/avm2/globals/flash/display/loaderinfo.rs | 2 +- core/src/tag_utils.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/avm2/globals/flash/display/loaderinfo.rs b/core/src/avm2/globals/flash/display/loaderinfo.rs index 691093bec..4a0061d33 100644 --- a/core/src/avm2/globals/flash/display/loaderinfo.rs +++ b/core/src/avm2/globals/flash/display/loaderinfo.rs @@ -94,7 +94,7 @@ pub fn bytes_total<'gc>( if let Some(loader_stream) = this.as_loader_stream() { match &*loader_stream { LoaderStream::SWF(movie, _) => { - return Ok(movie.data().len().into()); + return Ok(movie.compressed_length().into()); } } } diff --git a/core/src/tag_utils.rs b/core/src/tag_utils.rs index 3660694d5..bd325623a 100644 --- a/core/src/tag_utils.rs +++ b/core/src/tag_utils.rs @@ -28,6 +28,9 @@ pub struct SwfMovie { /// The suggest encoding for this SWF. encoding: &'static swf::Encoding, + + /// The compressed length of the entire datastream + compressed_length: usize, } impl SwfMovie { @@ -46,6 +49,7 @@ impl SwfMovie { url: None, parameters: PropertyMap::new(), encoding: swf::UTF_8, + compressed_length: 0, } } @@ -61,6 +65,7 @@ impl SwfMovie { url: source.url.clone(), parameters: source.parameters.clone(), encoding: source.encoding, + compressed_length: source.compressed_length, } } @@ -78,6 +83,7 @@ impl SwfMovie { /// Construct a movie based on the contents of the SWF datastream. pub fn from_data(swf_data: &[u8], url: Option) -> Result { + let compressed_length = swf_data.len(); let swf_buf = swf::read::decompress_swf(swf_data)?; let encoding = swf::SwfStr::encoding_for_version(swf_buf.header.version); Ok(Self { @@ -86,6 +92,7 @@ impl SwfMovie { url, parameters: PropertyMap::new(), encoding, + compressed_length, }) } @@ -130,6 +137,10 @@ impl SwfMovie { pub fn parameters_mut(&mut self) -> &mut PropertyMap { &mut self.parameters } + + pub fn compressed_length(&self) -> usize { + self.compressed_length + } } /// A shared-ownership reference to some portion of an SWF datastream.