From a69b80b4bbc89aa8ef6dc1e334eb8345c6595153 Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Wed, 17 Apr 2024 00:05:51 +0200 Subject: [PATCH] avm2: Allow splice() on a Vector with fixed=true --- core/src/avm2/vector.rs | 7 ++--- .../vector_splice_fixed_bug_compat/Test.as | 28 ++++++++++++++++++ .../vector_splice_fixed_bug_compat/output.txt | 4 +++ .../vector_splice_fixed_bug_compat/test.swf | Bin 0 -> 697 bytes .../vector_splice_fixed_bug_compat/test.toml | 1 + 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/Test.as create mode 100644 tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/output.txt create mode 100644 tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.swf create mode 100644 tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.toml diff --git a/core/src/avm2/vector.rs b/core/src/avm2/vector.rs index 4277278e9cfb..9a64affa6330 100644 --- a/core/src/avm2/vector.rs +++ b/core/src/avm2/vector.rs @@ -7,7 +7,7 @@ use crate::avm2::value::Value; use crate::avm2::Error; use gc_arena::Collect; use std::cmp::{max, min}; -use std::ops::{Index, RangeBounds}; +use std::ops::RangeBounds; use std::slice::SliceIndex; /// The vector storage portion of a vector object. @@ -401,10 +401,7 @@ impl<'gc> VectorStorage<'gc> { where R: Clone + SliceIndex<[Value<'gc>], Output = [Value<'gc>]> + RangeBounds, { - if self.is_fixed && self.storage.index(range.clone()).len() != replace_with.len() { - return Err("RangeError: Vector is fixed".into()); - } - + // NOTE: no fixed check here for bug compatibility Ok(self.storage.splice(range, replace_with).collect()) } } diff --git a/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/Test.as b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/Test.as new file mode 100644 index 000000000000..7e313e8ab40f --- /dev/null +++ b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/Test.as @@ -0,0 +1,28 @@ +// compiled with mxmlc + +import flash.utils.getQualifiedClassName; +import flash.utils.getTimer; +import flash.utils.ByteArray; + +var v = new Vector.(5, true); +trace(v.length); +try { + v.push(123); +} catch(e) { + trace("push exception caught"); +} +v.splice(0, 3); +trace("NO exception on splice") +trace(v.length); + +package { + import flash.display.MovieClip; + import flash.text.TextField; + + public class Test extends MovieClip { + public function Test(){ + + } + } +} + diff --git a/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/output.txt b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/output.txt new file mode 100644 index 000000000000..95f2dcd0f400 --- /dev/null +++ b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/output.txt @@ -0,0 +1,4 @@ +5 +push exception caught +NO exception on splice +2 diff --git a/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.swf b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..c10917c85e4347ce9b761ccd456391fc27242108 GIT binary patch literal 697 zcmV;q0!IB>S5q?I0{{T10ssJA001BW06YKujv4yj=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%3>H=An z_22MtaNQr2k>hrq+Lm{|M)X7aUYozc91k@F;ZJ^mGrkW;PKctrez5!~il!Hzxk0`_ zU{Si%(2Dp({k-sCk*&19X$}t-6&fGM&vKs1d7Tj-V2`!}L?nb5;h@531OLtKeWs+j zQM>)CWc^90myQP*Z;7<{ak|N!Mu@@dG<2*RouD-v*roacbrE7pM-IvcWPAigT#sl)q<_&H>m?%c=V6L$62;u z&Gaw7V+nZNOeJ-dH)_DP{bZ;mqh-_F-mdSb<$4aT0dR$4Rg)g}4Fp7hJh}rbud@84 z6MlI*;^@?C<8v&J|DreTH#h1o8V&gDM_3JsF5%XY?l?tu(-9Fow?eWMA6lIBE3iPbHd;E@^7Jc|yZ`AIvg$uH9 fz8DjHzdTLZ!-7FP^&lEdf@u{TcyP$={))6Zgh5}7 literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.toml b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm2/vector_splice_fixed_bug_compat/test.toml @@ -0,0 +1 @@ +num_frames = 1