From e9e4ceb61d4a3246fdbdbd3a2bbe787dfc36d1c1 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Wed, 27 Nov 2024 21:32:07 +0100 Subject: [PATCH] swf: Memcpy the swf header away instead of creating an entire new Vec --- swf/src/read.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/swf/src/read.rs b/swf/src/read.rs index 810e35936ef6..a57d6900e01e 100644 --- a/swf/src/read.rs +++ b/swf/src/read.rs @@ -136,7 +136,12 @@ pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result { frame_rate, num_frames, }; - let data = reader.get_ref().to_vec(); + let offset = reader.as_slice().as_ptr() as usize - data.as_ptr() as usize; + // Remove the header. + // As an alternative we could return the entire original buffer with header length, + // but that's a nontrivial API change, probably not worth the effort. + data.drain(..offset); + let mut reader = Reader::new(&data, version); // Parse the first two tags, searching for the FileAttributes and SetBackgroundColor tags. // This metadata is useful, so we want to return it along with the header.