From ce859c36d3935e270df822e5765ad40d76178220 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Wed, 23 Oct 2024 19:04:46 +0200 Subject: [PATCH] avm2: Use FP-compatible settings in ByteArray.compress --- core/src/avm2/bytearray.rs | 6 ++++-- .../swfs/avm2/bytearray_compress/Test.as | 18 +++++++++++++++++- .../swfs/avm2/bytearray_compress/output.txt | 3 +++ .../swfs/avm2/bytearray_compress/test.fla | Bin 4466 -> 0 bytes .../swfs/avm2/bytearray_compress/test.swf | Bin 1363 -> 969 bytes 5 files changed, 24 insertions(+), 3 deletions(-) delete mode 100644 tests/tests/swfs/avm2/bytearray_compress/test.fla diff --git a/core/src/avm2/bytearray.rs b/core/src/avm2/bytearray.rs index 79045ab407eb..65cffc15e508 100644 --- a/core/src/avm2/bytearray.rs +++ b/core/src/avm2/bytearray.rs @@ -229,11 +229,13 @@ impl ByteArrayStorage { let mut buffer = Vec::new(); let error: Option> = 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")] diff --git a/tests/tests/swfs/avm2/bytearray_compress/Test.as b/tests/tests/swfs/avm2/bytearray_compress/Test.as index cb205e901097..066f9c47192d 100644 --- a/tests/tests/swfs/avm2/bytearray_compress/Test.as +++ b/tests/tests/swfs/avm2/bytearray_compress/Test.as @@ -1,3 +1,5 @@ +// compiled with mxmlc + package { import flash.utils.ByteArray; import flash.utils.Endian; @@ -36,6 +38,8 @@ package { ba.uncompress("zlib"); print("uncompressed (zlib)", ba, true); + + checkZlibPrefix(); } function createByteArray(): ByteArray { @@ -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()); + } } -} \ No newline at end of file +} diff --git a/tests/tests/swfs/avm2/bytearray_compress/output.txt b/tests/tests/swfs/avm2/bytearray_compress/output.txt index 54bccdb4e601..d70b0d854347 100644 --- a/tests/tests/swfs/avm2/bytearray_compress/output.txt +++ b/tests/tests/swfs/avm2/bytearray_compress/output.txt @@ -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 diff --git a/tests/tests/swfs/avm2/bytearray_compress/test.fla b/tests/tests/swfs/avm2/bytearray_compress/test.fla deleted file mode 100644 index f4c23c5d47e41bc74546e7a6fd51285c05dce72a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4466 zcmbW5byU;s`^U%Vl#-BCN>o6UknWnq2nhj4%`qH3kQQkXk&X$YK@b_zA&9^LMNqmW z6lq2Y(!ZgPkB=U||NQQq>s;Gs*Zcb1=d<_Oxn4K;Iw27w06+!+98jwo*T+qVu>t^q zlfYjBIKmyFNN*RYwTlY^ZflK%J3EPZI@t+Z+d11ng}rVgz`w~ksO<>J@v@URkt3n* z$nRAKdZuPVDu&{}m*Xq`T_@$*TFM4W24*7vyXvH|j+&8@ke06cKV?8NvhQ0D%#8fF zN&o<)5&;0G@MWrcI;zgL9*$5a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{fxyTwaxkc+_TBxL&c*OncViVhr5xOg*@)7By*O>d_YMnciNv$WKHDLbVXU{?-Ei};@3={HB3EQZ4^ zXS@RGg6cN}&iA6%0!niIT0<srbxu(qQ)ZfvT6`%xa_$lS9B+O=D1M^( zchTeD={VcK5zzlmH@^cSKd~1bJHGBDPR1b{xRZ#Xx1%c51&T*iTWec;C=7pjjuZ$W z0T2NQ0GGd00R9r7@i~5a`VC?K9|TMQWCZ*|=sy|w3I4ClCFJ%Kzx_sU9DHfHU}?o&FU62~)qsgLuUH z_n!Ynt3O-(IlumDkx%^BY4%rxzdPhtgHW2k`{noN_NQZh=_~R2zxe0p22OsPznzo( eY5>GD=Fd|T@O5I6lW)lJFMa&OQ93!70Q?{5i)vZ` diff --git a/tests/tests/swfs/avm2/bytearray_compress/test.swf b/tests/tests/swfs/avm2/bytearray_compress/test.swf index 47c62d4649ce94349f22be020e452374a5e06c77..2cb295c70a3fbf800983c608bdaa6cd0d791954f 100644 GIT binary patch literal 969 zcmV;)12+6xS5q?J1polJ0{{SB001BW06YKujv4yj=Vl0?JwAo?b#KsqVJOXhixy4a z1v37mOh!q!duw(1D_l1z3z0VgHxB9Y;ryOt+H4UaGwq-bc5tB0m@amJ@Zeci1_!QZnT84W^-kDu!b~qNjlRVSVp3_xhTH3JNC+2)1J*>=-p>|kv2*_BK)@TdzxW~s5 zRX~U5S-?);A+G44YL3M0*f=<)^i{biPBGOIR$lYO&{zPAusrYQ+MNi=aD#T4!$ zPkS*y6Mr~&jb2>K)qny&rD&(ESY3$E?lK{?1zUms&{I3Vb0+e_VuJ%g*!>e*m8J?242(Fwy)sIf>4Gx4!fXex2K-_C7YHL zq&0(nMSic+4w|T_j0`3+LiHl*2)R@|%lI+-mAWv9&z^FRB_KhH$-U(3=4#W>rH}|5 z=M<8Y^CpY2DttzYuI3nDQ-E+2u)qb*{BO=bOu1;9b3lw%h`5d2j%d-)Z#%$QH1WQr z0lLv}uys_J8XcR=WlFq3qJ@FIJcS=JRGQ4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