Skip to content

Commit

Permalink
avm2: Use FP-compatible settings in ByteArray.compress
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 committed Oct 23, 2024
1 parent 2b83e3a commit ce859c3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
6 changes: 4 additions & 2 deletions core/src/avm2/bytearray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,13 @@ impl ByteArrayStorage {
let mut buffer = Vec::new();
let error: Option<Box<dyn std::error::Error>> = match algorithm {
CompressionAlgorithm::Zlib => {
let mut encoder = ZlibEncoder::new(&*self.bytes, Compression::fast());
// Note: some content is sensitive to compression type
// (as it's visible in the header)
let mut encoder = ZlibEncoder::new(&*self.bytes, Compression::best());
encoder.read_to_end(&mut buffer).err().map(|e| e.into())
}
CompressionAlgorithm::Deflate => {
let mut encoder = DeflateEncoder::new(&*self.bytes, Compression::fast());
let mut encoder = DeflateEncoder::new(&*self.bytes, Compression::best());
encoder.read_to_end(&mut buffer).err().map(|e| e.into())
}
#[cfg(feature = "lzma")]
Expand Down
18 changes: 17 additions & 1 deletion tests/tests/swfs/avm2/bytearray_compress/Test.as
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compiled with mxmlc

package {
import flash.utils.ByteArray;
import flash.utils.Endian;
Expand Down Expand Up @@ -36,6 +38,8 @@ package {

ba.uncompress("zlib");
print("uncompressed (zlib)", ba, true);

checkZlibPrefix();
}

function createByteArray(): ByteArray {
Expand Down Expand Up @@ -68,5 +72,17 @@ package {

trace("");
}

// Issue 13773: gemcraft labirynth
// Requires zlib->base64 values to start with "eN".
// (which means binary header [120, 218])
function checkZlibPrefix() {
trace("Checking zlib header:")
var ba = createByteArray();
ba.compress("zlib");
ba.position = 0;
trace(ba.readUnsignedByte());
trace(ba.readUnsignedByte());
}
}
}
}
3 changes: 3 additions & 0 deletions tests/tests/swfs/avm2/bytearray_compress/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ uncompressed (zlib) position is at 0
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99


Checking zlib header:
120
218
Binary file removed tests/tests/swfs/avm2/bytearray_compress/test.fla
Binary file not shown.
Binary file modified tests/tests/swfs/avm2/bytearray_compress/test.swf
Binary file not shown.

0 comments on commit ce859c3

Please sign in to comment.