From 404b4b0a90a5862606d115f0333bd838411e1bce Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 25 Jul 2023 14:08:55 -0400 Subject: [PATCH 1/2] avm2: Fix handling of default domain memory Whenever `ApplicationDomain.domainMemory` is set to `null` (which is the default value), domain memory opcodes read from use hidden ByteArray in the domain. This hidden bytearray object is re-used if `ApplicationDomain.domainMemory` is ever set back to `null`. --- core/src/avm2/domain.rs | 56 ++++- .../globals/flash/system/ApplicationDomain.as | 5 + .../flash/system/application_domain.rs | 19 +- tests/tests/swfs/avm2/domain_memory/Test.as | 218 ++++++++++++++++++ .../tests/swfs/avm2/domain_memory/output.txt | 17 ++ tests/tests/swfs/avm2/domain_memory/test.as | 180 --------------- tests/tests/swfs/avm2/domain_memory/test.swf | Bin 991 -> 2182 bytes 7 files changed, 300 insertions(+), 195 deletions(-) create mode 100644 tests/tests/swfs/avm2/domain_memory/Test.as delete mode 100644 tests/tests/swfs/avm2/domain_memory/test.as diff --git a/core/src/avm2/domain.rs b/core/src/avm2/domain.rs index 84ebb0db983f..e03482e31847 100644 --- a/core/src/avm2/domain.rs +++ b/core/src/avm2/domain.rs @@ -12,6 +12,7 @@ use gc_arena::{Collect, GcCell, MutationContext}; use ruffle_wstr::WStr; use super::class::Class; +use super::error::error; use super::string::AvmString; /// Represents a set of scripts and movies that share traits across different @@ -40,8 +41,12 @@ struct DomainData<'gc> { /// player globals setup (we need a global domain to put globals into, but /// that domain needs the bytearray global) pub domain_memory: Option>, + + pub default_domain_memory: Option>, } +const MIN_DOMAIN_MEMORY_LENGTH: usize = 1024; + impl<'gc> Domain<'gc> { /// Create a new domain with no parent. /// @@ -62,6 +67,7 @@ impl<'gc> Domain<'gc> { classes: PropertyMap::new(), parent, domain_memory: None, + default_domain_memory: None, }, )) } @@ -82,6 +88,7 @@ impl<'gc> Domain<'gc> { classes: PropertyMap::new(), parent: Some(parent), domain_memory: None, + default_domain_memory: None, }, )); @@ -294,6 +301,15 @@ impl<'gc> Domain<'gc> { self.0.write(mc).classes.insert(class.read().name(), class); } + pub fn is_default_domain_memory(&self) -> bool { + let read = self.0.read(); + read.domain_memory.expect("Missing domain memory").as_ptr() + == read + .default_domain_memory + .expect("Missing default domain memory") + .as_ptr() + } + pub fn domain_memory(&self) -> ByteArrayObject<'gc> { self.0 .read() @@ -303,10 +319,25 @@ impl<'gc> Domain<'gc> { pub fn set_domain_memory( &self, - mc: MutationContext<'gc, '_>, - domain_memory: ByteArrayObject<'gc>, - ) { - self.0.write(mc).domain_memory = Some(domain_memory) + activation: &mut Activation<'_, 'gc>, + domain_memory: Option>, + ) -> Result<(), Error<'gc>> { + let mut write = self.0.write(activation.context.gc_context); + if let Some(domain_memory) = domain_memory { + if domain_memory.storage().len() < MIN_DOMAIN_MEMORY_LENGTH { + return Err(Error::AvmError(error( + activation, + "Error #1504: End of file.", + 1504, + )?)); + } + } + write.domain_memory = Some(domain_memory.unwrap_or_else(|| { + write + .default_domain_memory + .expect("Default domain memory not initialized") + })); + Ok(()) } /// Allocate the default domain memory for this domain, if it does not @@ -325,12 +356,21 @@ impl<'gc> Domain<'gc> { domain_memory .as_bytearray_mut(activation.context.gc_context) .unwrap() - .set_length(1024); + .set_length(MIN_DOMAIN_MEMORY_LENGTH); let mut write = self.0.write(activation.context.gc_context); - write - .domain_memory - .get_or_insert(domain_memory.as_bytearray_object().unwrap()); + + assert!( + write.domain_memory.is_none(), + "Already initialized domain memory!" + ); + assert!( + write.default_domain_memory.is_none(), + "Already initialized domain memory!" + ); + + write.domain_memory = Some(domain_memory.as_bytearray_object().unwrap()); + write.default_domain_memory = Some(domain_memory.as_bytearray_object().unwrap()); Ok(()) } diff --git a/core/src/avm2/globals/flash/system/ApplicationDomain.as b/core/src/avm2/globals/flash/system/ApplicationDomain.as index 21d0f38a289e..ca589e5cb234 100644 --- a/core/src/avm2/globals/flash/system/ApplicationDomain.as +++ b/core/src/avm2/globals/flash/system/ApplicationDomain.as @@ -19,5 +19,10 @@ package flash.system { public native function hasDefinition(name:String):Boolean; public native function getQualifiedDefinitionNames():Vector.; + + public static function get MIN_DOMAIN_MEMORY_LENGTH():uint { + return 1024; + } + } } diff --git a/core/src/avm2/globals/flash/system/application_domain.rs b/core/src/avm2/globals/flash/system/application_domain.rs index 72613f5b79c2..a4509beaf46b 100644 --- a/core/src/avm2/globals/flash/system/application_domain.rs +++ b/core/src/avm2/globals/flash/system/application_domain.rs @@ -140,11 +140,12 @@ pub fn set_domain_memory<'gc>( this: Object<'gc>, args: &[Value<'gc>], ) -> Result, Error<'gc>> { - if let Some(Value::Object(arg)) = args.get(0) { - if let Some(bytearray_obj) = arg.as_bytearray_object() { - if let Some(appdomain) = this.as_application_domain() { - appdomain.set_domain_memory(activation.context.gc_context, bytearray_obj); - } + if let Some(appdomain) = this.as_application_domain() { + let obj = args.try_get_object(activation, 0); + if let Some(obj) = obj { + appdomain.set_domain_memory(activation, Some(obj.as_bytearray_object().unwrap()))?; + } else { + appdomain.set_domain_memory(activation, None)?; } } @@ -158,8 +159,12 @@ pub fn get_domain_memory<'gc>( _args: &[Value<'gc>], ) -> Result, Error<'gc>> { if let Some(appdomain) = this.as_application_domain() { - let bytearray_object: Object<'gc> = appdomain.domain_memory().into(); - return Ok(bytearray_object.into()); + if appdomain.is_default_domain_memory() { + return Ok(Value::Null); + } else { + let bytearray_object: Object<'gc> = appdomain.domain_memory().into(); + return Ok(bytearray_object.into()); + } } Ok(Value::Undefined) diff --git a/tests/tests/swfs/avm2/domain_memory/Test.as b/tests/tests/swfs/avm2/domain_memory/Test.as new file mode 100644 index 000000000000..b90fe0428e23 --- /dev/null +++ b/tests/tests/swfs/avm2/domain_memory/Test.as @@ -0,0 +1,218 @@ +package { + import flash.utils.Endian; + import avm2.intrinsics.memory.si8; + import avm2.intrinsics.memory.si16; + import avm2.intrinsics.memory.si32; + import avm2.intrinsics.memory.sf32; + import avm2.intrinsics.memory.sf64; + import avm2.intrinsics.memory.li8; + import avm2.intrinsics.memory.li16; + import avm2.intrinsics.memory.li32; + import avm2.intrinsics.memory.lf32; + import avm2.intrinsics.memory.lf64; + import avm2.intrinsics.memory.sxi1; + import avm2.intrinsics.memory.sxi8; + import avm2.intrinsics.memory.sxi16; + import flash.system.ApplicationDomain; + import flash.utils.ByteArray; + import flash.display.Sprite; + + public class Test extends Sprite { + public function Test() { + init(); + } + + private function init():void { + trace("// ApplicationDomain.currentDomain.domainMemory"); + trace(ApplicationDomain.currentDomain.domainMemory); + si8(65, 0); + + trace("// ApplicationDomain.currentDomain.domainMemory after si8(65, 0)"); + trace(ApplicationDomain.currentDomain.domainMemory); + + trace("// li8(0) after si8(65, 0)"); + trace(li8(0)); + + trace("// ApplicationDomain.currentDomain.domainMemory after li8(0)"); + trace(ApplicationDomain.currentDomain.domainMemory); + + si8(255, 0); + trace("// li8(0) after si8(255, 0)"); + trace(li8(0)); + + si8(0xFFFFFFFF, 0); + trace("// li8(0) after si8(0xFFFFFFFF, 0)"); + trace(li8(0)); + trace("// li8(1) after si8(0xFFFFFFFF, 0)"); + trace(li8(1)); + trace("// li8(1) after si8(0xFFFFFFFF, 0)"); + trace(li8(2)); + trace("// li8(1) after si8(0xFFFFFFFF, 0)"); + trace(li8(3)); + + si16(256, 0); + trace("// li8(0) after si16(256, 0)"); + trace(li8(0)); + trace("// li8(1) after si16(256, 0)"); + trace(li8(1)); + trace("// li16(0) after si16(256, 0)"); + trace(li16(0)); + + si16(0xFFFF, 0); + trace("// li8(0) after si16(0xFFFF, 0)"); + trace(li8(0)); + trace("// li8(1) after si16(0xFFFF, 0)"); + trace(li8(1)); + trace("// li16(0) after si16(0xFFFF, 0)"); + trace(li16(0)); + + si16(0xFFFFFFFF, 0); + trace("// li8(0) after si16(0xFFFFFFFF, 0)"); + trace(li8(0)); + trace("// li8(1) after si16(0xFFFFFFFF, 0)"); + trace(li8(1)); + trace("// li8(1) after si16(0xFFFFFFFF, 0)"); + trace(li8(2)); + trace("// li8(1) after si16(0xFFFFFFFF, 0)"); + trace(li8(3)); + + si32(0xFFFFFFFF, 0); + trace("// li8(0) after si32(0xFFFFFFFF, 0)"); + trace(li8(0)); + trace("// li8(1) after si32(0xFFFFFFFF, 0)"); + trace(li8(1)); + trace("// li8(2) after si32(0xFFFFFFFF, 0)"); + trace(li8(2)); + trace("// li8(3) after si32(0xFFFFFFFF, 0)"); + trace(li8(3)); + trace("// li32(0) after si32(0xFFFFFFFF, 0)"); + trace(li32(0)); + + sf32(0xFFFFFFFF, 0); + trace("// li8(0) after sf32(0xFFFFFFFF, 0)"); + trace(li8(0)); + trace("// li8(1) after sf32(0xFFFFFFFF, 0)"); + trace(li8(1)); + trace("// li8(2) after sf32(0xFFFFFFFF, 0)"); + trace(li8(2)); + trace("// li8(3) after sf32(0xFFFFFFFF, 0)"); + trace(li8(3)); + trace("// li32(0) after sf32(0xFFFFFFFF, 0)"); + trace(li32(0)); + trace("// lf32(0) after sf32(0xFFFFFFFF, 0)"); + trace(lf32(0)); + + sf32(1234.7654321, 0); + trace("// li8(0) after sf32(1234.7654321, 0)"); + trace(li8(0)); + trace("// li8(1) after sf32(1234.7654321, 0)"); + trace(li8(1)); + trace("// li8(2) after sf32(1234.7654321, 0)"); + trace(li8(2)); + trace("// li8(3) after sf32(1234.7654321, 0)"); + trace(li8(3)); + trace("// li32(0) after sf32(1234.7654321, 0)"); + trace(li32(0)); + trace("// lf32(0) after sf32(1234.7654321, 0)"); + trace(lf32(0)); + + sf64(999999.9999999999, 0); + trace("// li8(0) after sf64(999999.9999999999, 0)"); + trace(li8(0)); + trace("// li8(1) after sf64(999999.9999999999, 0)"); + trace(li8(1)); + trace("// li8(2) after sf64(999999.9999999999, 0)"); + trace(li8(2)); + trace("// li8(3) after sf64(999999.9999999999, 0)"); + trace(li8(3)); + trace("// li8(4) after sf64(999999.9999999999, 0)"); + trace(li8(4)); + trace("// li8(5) after sf64(999999.9999999999, 0)"); + trace(li8(5)); + trace("// li8(6) after sf64(999999.9999999999, 0)"); + trace(li8(6)); + trace("// li8(7) after sf64(999999.9999999999, 0)"); + trace(li8(7)); + + trace("// li32(0) after sf64(999999.9999999999, 0)"); + trace(li32(0)); + trace("// li32(4) after sf64(999999.9999999999, 0)"); + trace(li32(4)); + trace("// lf32(0) after sf64(999999.9999999999, 0)"); + trace(lf32(0)); + trace("// lf32(4) after sf64(999999.9999999999, 0)"); + trace(lf32(0)); + trace("// lf64(0) after sf64(999999.9999999999, 0)"); + trace(lf64(0)); + + trace("// sxi1(0)"); + trace(sxi1(0)); + + trace("// sxi1(1)"); + trace(sxi1(1)); + + trace("// sxi1(10)"); + trace(sxi1(10)); + + trace("// sxi1(255)"); + trace(sxi1(255)); + + trace("// sxi8(0)"); + trace(sxi8(0)); + + trace("// sxi8(1)"); + trace(sxi8(1)); + + trace("// sxi8(10)"); + trace(sxi8(10)); + + trace("// sxi8(255)"); + trace(sxi8(255)); + + trace("// sxi16(0)"); + trace(sxi16(0)); + + trace("// sxi16(1)"); + trace(sxi16(1)); + + trace("// sxi16(10)"); + trace(sxi16(10)); + + trace("// sxi16(255)"); + trace(sxi16(255)); + + trace("// si8(42, 0)"); + si8(42, 0); + + var bytes = new ByteArray(); + bytes.length = 1024; + trace("// ApplicationDomain.currentDomain.domainMemory = bytes"); + ApplicationDomain.currentDomain.domainMemory = bytes; + + trace("// li8(0) after explicit overwrite"); + trace(li8(0)); + + trace("// si8(45, 0)"); + si8(45, 0); + + trace("// ApplicationDomain.currentDomain.domainMemory = null"); + ApplicationDomain.currentDomain.domainMemory = null; + + trace("// li8(0)"); + trace(li8(0)); + + trace("// ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH") + trace(ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) + + var bytes = new ByteArray(); + bytes.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH - 1; + try { + ApplicationDomain.currentDomain.domainMemory = bytes; + trace("FAILED - write should have thrown an error") + } catch (e) { + trace("Caught error: " + e); + } + + } + } +} diff --git a/tests/tests/swfs/avm2/domain_memory/output.txt b/tests/tests/swfs/avm2/domain_memory/output.txt index 2a3eaf2b49ec..1b261468d460 100644 --- a/tests/tests/swfs/avm2/domain_memory/output.txt +++ b/tests/tests/swfs/avm2/domain_memory/output.txt @@ -1,5 +1,11 @@ +// ApplicationDomain.currentDomain.domainMemory +null +// ApplicationDomain.currentDomain.domainMemory after si8(65, 0) +null // li8(0) after si8(65, 0) 65 +// ApplicationDomain.currentDomain.domainMemory after li8(0) +null // li8(0) after si8(255, 0) 255 // li8(0) after si8(0xFFFFFFFF, 0) @@ -114,3 +120,14 @@ NaN 10 // sxi16(255) 255 +// si8(42, 0) +// ApplicationDomain.currentDomain.domainMemory = bytes +// li8(0) after explicit overwrite +0 +// si8(45, 0) +// ApplicationDomain.currentDomain.domainMemory = null +// li8(0) +42 +// ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH +1024 +Caught error: Error: Error #1504: End of file. diff --git a/tests/tests/swfs/avm2/domain_memory/test.as b/tests/tests/swfs/avm2/domain_memory/test.as deleted file mode 100644 index d5c46ef1a4bd..000000000000 --- a/tests/tests/swfs/avm2/domain_memory/test.as +++ /dev/null @@ -1,180 +0,0 @@ -package -{ - import flash.utils.Endian; - import avm2.intrinsics.memory.si8; - import avm2.intrinsics.memory.si16; - import avm2.intrinsics.memory.si32; - import avm2.intrinsics.memory.sf32; - import avm2.intrinsics.memory.sf64; - import avm2.intrinsics.memory.li8; - import avm2.intrinsics.memory.li16; - import avm2.intrinsics.memory.li32; - import avm2.intrinsics.memory.lf32; - import avm2.intrinsics.memory.lf64; - import avm2.intrinsics.memory.sxi1; - import avm2.intrinsics.memory.sxi8; - import avm2.intrinsics.memory.sxi16; - import flash.system.ApplicationDomain; - import flash.utils.ByteArray; - import flash.display.Sprite; - - public class Test extends Sprite - { - public function Test() - { - init(); - } - - private function init(): void - { - si8(65, 0); - trace("// li8(0) after si8(65, 0)"); - trace(li8(0)); - - si8(255, 0); - trace("// li8(0) after si8(255, 0)"); - trace(li8(0)); - - si8(0xFFFFFFFF, 0); - trace("// li8(0) after si8(0xFFFFFFFF, 0)"); - trace(li8(0)); - trace("// li8(1) after si8(0xFFFFFFFF, 0)"); - trace(li8(1)); - trace("// li8(1) after si8(0xFFFFFFFF, 0)"); - trace(li8(2)); - trace("// li8(1) after si8(0xFFFFFFFF, 0)"); - trace(li8(3)); - - si16(256, 0); - trace("// li8(0) after si16(256, 0)"); - trace(li8(0)); - trace("// li8(1) after si16(256, 0)"); - trace(li8(1)); - trace("// li16(0) after si16(256, 0)"); - trace(li16(0)); - - si16(0xFFFF, 0); - trace("// li8(0) after si16(0xFFFF, 0)"); - trace(li8(0)); - trace("// li8(1) after si16(0xFFFF, 0)"); - trace(li8(1)); - trace("// li16(0) after si16(0xFFFF, 0)"); - trace(li16(0)); - - si16(0xFFFFFFFF, 0); - trace("// li8(0) after si16(0xFFFFFFFF, 0)"); - trace(li8(0)); - trace("// li8(1) after si16(0xFFFFFFFF, 0)"); - trace(li8(1)); - trace("// li8(1) after si16(0xFFFFFFFF, 0)"); - trace(li8(2)); - trace("// li8(1) after si16(0xFFFFFFFF, 0)"); - trace(li8(3)); - - si32(0xFFFFFFFF, 0); - trace("// li8(0) after si32(0xFFFFFFFF, 0)"); - trace(li8(0)); - trace("// li8(1) after si32(0xFFFFFFFF, 0)"); - trace(li8(1)); - trace("// li8(2) after si32(0xFFFFFFFF, 0)"); - trace(li8(2)); - trace("// li8(3) after si32(0xFFFFFFFF, 0)"); - trace(li8(3)); - trace("// li32(0) after si32(0xFFFFFFFF, 0)"); - trace(li32(0)); - - sf32(0xFFFFFFFF, 0); - trace("// li8(0) after sf32(0xFFFFFFFF, 0)"); - trace(li8(0)); - trace("// li8(1) after sf32(0xFFFFFFFF, 0)"); - trace(li8(1)); - trace("// li8(2) after sf32(0xFFFFFFFF, 0)"); - trace(li8(2)); - trace("// li8(3) after sf32(0xFFFFFFFF, 0)"); - trace(li8(3)); - trace("// li32(0) after sf32(0xFFFFFFFF, 0)"); - trace(li32(0)); - trace("// lf32(0) after sf32(0xFFFFFFFF, 0)"); - trace(lf32(0)); - - sf32(1234.7654321, 0); - trace("// li8(0) after sf32(1234.7654321, 0)"); - trace(li8(0)); - trace("// li8(1) after sf32(1234.7654321, 0)"); - trace(li8(1)); - trace("// li8(2) after sf32(1234.7654321, 0)"); - trace(li8(2)); - trace("// li8(3) after sf32(1234.7654321, 0)"); - trace(li8(3)); - trace("// li32(0) after sf32(1234.7654321, 0)"); - trace(li32(0)); - trace("// lf32(0) after sf32(1234.7654321, 0)"); - trace(lf32(0)); - - sf64(999999.9999999999, 0); - trace("// li8(0) after sf64(999999.9999999999, 0)"); - trace(li8(0)); - trace("// li8(1) after sf64(999999.9999999999, 0)"); - trace(li8(1)); - trace("// li8(2) after sf64(999999.9999999999, 0)"); - trace(li8(2)); - trace("// li8(3) after sf64(999999.9999999999, 0)"); - trace(li8(3)); - trace("// li8(4) after sf64(999999.9999999999, 0)"); - trace(li8(4)); - trace("// li8(5) after sf64(999999.9999999999, 0)"); - trace(li8(5)); - trace("// li8(6) after sf64(999999.9999999999, 0)"); - trace(li8(6)); - trace("// li8(7) after sf64(999999.9999999999, 0)"); - trace(li8(7)); - - trace("// li32(0) after sf64(999999.9999999999, 0)"); - trace(li32(0)); - trace("// li32(4) after sf64(999999.9999999999, 0)"); - trace(li32(4)); - trace("// lf32(0) after sf64(999999.9999999999, 0)"); - trace(lf32(0)); - trace("// lf32(4) after sf64(999999.9999999999, 0)"); - trace(lf32(0)); - trace("// lf64(0) after sf64(999999.9999999999, 0)"); - trace(lf64(0)); - - trace("// sxi1(0)"); - trace(sxi1(0)); - - trace("// sxi1(1)"); - trace(sxi1(1)); - - trace("// sxi1(10)"); - trace(sxi1(10)); - - trace("// sxi1(255)"); - trace(sxi1(255)); - - trace("// sxi8(0)"); - trace(sxi8(0)); - - trace("// sxi8(1)"); - trace(sxi8(1)); - - trace("// sxi8(10)"); - trace(sxi8(10)); - - trace("// sxi8(255)"); - trace(sxi8(255)); - - trace("// sxi16(0)"); - trace(sxi16(0)); - - trace("// sxi16(1)"); - trace(sxi16(1)); - - trace("// sxi16(10)"); - trace(sxi16(10)); - - trace("// sxi16(255)"); - trace(sxi16(255)); - } - } -} diff --git a/tests/tests/swfs/avm2/domain_memory/test.swf b/tests/tests/swfs/avm2/domain_memory/test.swf index c6f2c52c40700ee7df7d2be5dd75f20c3287d216..b162f3939bf30e14b8a21a507f2b260c6666e5d0 100644 GIT binary patch literal 2182 zcmV;12zmEIS5q>Y6aWBt0i{^$a~oF`zjq~jRnw@KQj)>>LwYV~4w{o<7r3JmY}z`($?15*YD28Ip{4DW&AHFR)b0$)1}ANW@B z7npN*@9IjHm87sAtb2dwcYf!bdp3K|WD|M+iBRWj2pz^K-t!nj=+1$^V}!=fZsv2+ zx^9@+VqwA`3aWnT>}2b>kxEAw;xiIh3uY8{6aI{4m79yf_c(E*($+ftHgCPX=FJ+BumQwaq_ zen!cf5GKfjK-N*nzLd@BhE&k<`h-80q**T7Mej$$H-T(HCqhB60 z_ag+IM|s^?)l;Y&1rg9a$cxaM;PzH*{Pn^cU6((14mLY?UJk}qz1c$6@-9L7sCltu zWG%hJKFMGzYnF1_)}iI))#9>MTu$j}N`-=!GkUJ%fy47e#>S4i_M}xb>PVwQ!_)uI znV&gBGYe{F)5;b!r^zz3q^>B66yt9}+-_1Zxn>yfim{#3xjDOWJ$2-Er$lqhwDf#O zjc0qc=ef5TNz&35bl=R5^+!gCqz?E%AO|~jpw2Y@ziB&aNA}VUkJvH&d)d^@8TQb$ zTuP`qty;>_dX-S5KRgnl{;sjgpBsRS9-TV+aO$Z& zy3{Dy3ilBTv$?z4`aoUEePmrws``iANVgSgGdHs#;8vEQfi@QnsRQlq8g2-eL+>O; zAM3BsVOgP%!PkDIqC-FDu4V)rTuoT3105^?y&y)M9b9_DVfvo7oQIn`W*FL5n{(@~ zS=pS~oYM=dR_0*MtPynv5V;nNJA=sl$_skZnkvE^nl0$Y@mkVs0WMw*=B;(zAs(r< z*N7Z-Z2CGKNu$&BhuSqOnbD1A$AA9}406|u?7C*@R~Msn3^~E3WIn0J7KdO`RU--= z;jC<76waY;*m%HXB27s4T;txym2T^sbjZzGQW3`Y4SOo1M@$dZzT+crKTu&Umumqx zXMhOoDKIyCbvZsi7lWU<>ACrZTgz9buU=TXc({>aa3(f;WjZbeBs)n7#__dWO3J`M zE?F6)xKWU_f}|Tp(deAg)>bo?vx!Pr_pTSSsjgk8&n7dcH61lw>#6H;Z;ie3YV2$GmB9~qwCmHw@mwuYa47}k;Q_Y*CkAb&jGz!b| zvoziWwLM3kV7A*l-t**11}^h>3DVC%jmKLd0}M>^cquZ-K;4N)1Et9+2Cm9z43_1r z0=>19c!3aRdyyxRBLN2Hc@hN@WMGjeQ6dTh-^r6Oh{`~dCt;Bg1J_s*8;VCplQh9i z5@xn7p2WMz5Ch-MlXwpqX5f2y67M7KYkY?%aTgQ%0#f;xuD^8T?V`rYra{OwKU);}Ft?KY__OgFgvuH_oRp znPBjztKiRIGRff20_=wWJSJxu`~`rovGo@*Imeb?!ZLQ@FJls8@K>cU^eQshP2$){sxmPGWS1Kx&IlH=NuTKy@AuMuz{rh;v@ywHefP-6%uPI|CML+H%y)f zYWW`S_93*bK7$7TF{qx(W18xHOqLUEuYmp71^kEhH{1W!j@sxIg>V?b1tv*iH22JQbuItPpY I0{QsGC>wM%EdT%j literal 991 zcmV<510eibS5qt14FCYn0{{SB001BW06YKujv4yj=Vl0?JwAo?b#KsqVKo~Xixy4a 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&{I3Vb0K`e5L>7O z!EeL+nSsXceoI1kb$fG#wT76f%_-##WKi)+>yKwuZ7{@qx^#RorjqwqUiDDdDiEx% zXzQ|BgoP^`#|343dDP7{sE3Hzc3+&KdxDdVQff{=&_Gh|xMFepA(MMP<)WXEkWdtf zJqymj(T|l%SsTG!iU#%89wX?n&py&gaJwS-eJH&vbPj>G_Rh1M7JSk40()jKFEwHW z?{~jhI-Z3BM>F=vg1!Se4M zsjY80g;OQfYw25!V=t&9Zl=v)N`iSvC`w!$zD$j35jT8G?w#LCdR@*=%yj_Vexv7y zQD^eS{}O~v!^HGdvjY}26DH{OcCW}J{;mvkSUJVbHRvv;-G6d;!z{s=tIQ&aGcDgYI$K|B7m zsGb{)+Hq<3+L6!2qLJ|EKSu6Mk5;(@B zzva5^{cJ$Cc>UQdTvzk@1g@}RoF8a->qTA5W+C~t_%(Y{s}kEc*YOFr9ZsM&V>x76 z-_&#tzyn0YQ^c65P<}42Tdg`>-11ZXXIB)^88O4ca7|#joZgcT`zG~|rW%5yA>ej8 z=!)N>N!y*^{taZ*D@yYMKK^MnU3k`+z=Rpg3QMq1Sv;atoeAwSdJ6S1UbM3)&u(2X zdrYLSVNJ@b6~lgjb@wsUa+v2+Hi~Qh3X;M2m1W~ZlXlPaA N6piY}wg0l;Xy7Xo>K*_9 From 584e84d56b705530ae764e9927d199ab3047598b Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 26 Jul 2023 10:42:15 -0400 Subject: [PATCH 2/2] Address review comments --- core/src/avm2/domain.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/src/avm2/domain.rs b/core/src/avm2/domain.rs index e03482e31847..754de544eb3a 100644 --- a/core/src/avm2/domain.rs +++ b/core/src/avm2/domain.rs @@ -323,7 +323,7 @@ impl<'gc> Domain<'gc> { domain_memory: Option>, ) -> Result<(), Error<'gc>> { let mut write = self.0.write(activation.context.gc_context); - if let Some(domain_memory) = domain_memory { + let memory = if let Some(domain_memory) = domain_memory { if domain_memory.storage().len() < MIN_DOMAIN_MEMORY_LENGTH { return Err(Error::AvmError(error( activation, @@ -331,12 +331,13 @@ impl<'gc> Domain<'gc> { 1504, )?)); } - } - write.domain_memory = Some(domain_memory.unwrap_or_else(|| { + domain_memory + } else { write .default_domain_memory .expect("Default domain memory not initialized") - })); + }; + write.domain_memory = Some(memory); Ok(()) } @@ -369,8 +370,10 @@ impl<'gc> Domain<'gc> { "Already initialized domain memory!" ); - write.domain_memory = Some(domain_memory.as_bytearray_object().unwrap()); - write.default_domain_memory = Some(domain_memory.as_bytearray_object().unwrap()); + let bytearray = domain_memory.as_bytearray_object().unwrap(); + + write.domain_memory = Some(bytearray); + write.default_domain_memory = Some(bytearray); Ok(()) }