From 28a3c7178a805ddb7027d30738b0e58acf94147e Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Tue, 26 Dec 2023 18:33:32 +0100 Subject: [PATCH] avm2: Check the text.engine.FontDescription properties before setting --- .../flash/text/engine/FontDescription.as | 36 +++++++++++- .../avm2/text_engine_fontdescription/Test.as | 52 ++++++++++++++++++ .../text_engine_fontdescription/output.txt | 27 +++++++++ .../avm2/text_engine_fontdescription/test.swf | Bin 0 -> 1398 bytes .../text_engine_fontdescription/test.toml | 1 + 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 tests/tests/swfs/avm2/text_engine_fontdescription/Test.as create mode 100644 tests/tests/swfs/avm2/text_engine_fontdescription/output.txt create mode 100644 tests/tests/swfs/avm2/text_engine_fontdescription/test.swf create mode 100644 tests/tests/swfs/avm2/text_engine_fontdescription/test.toml diff --git a/core/src/avm2/globals/flash/text/engine/FontDescription.as b/core/src/avm2/globals/flash/text/engine/FontDescription.as index 7db9966b2c96..38ae97256ff0 100644 --- a/core/src/avm2/globals/flash/text/engine/FontDescription.as +++ b/core/src/avm2/globals/flash/text/engine/FontDescription.as @@ -14,8 +14,6 @@ package flash.text.engine { private var _cffHinting:String; - - public function FontDescription(fontName:String = "_serif", fontWeight:String = "normal", fontPosture:String = "normal", fontLookup:String = "device", renderingMode:String = "cff", cffHinting:String = "horizontalStem") { this.fontName = fontName; @@ -31,6 +29,8 @@ package flash.text.engine { } public function set fontName(value:String):void { + if (value == null) throwNonNull("fontName"); + this._fontName = value; } @@ -39,6 +39,11 @@ package flash.text.engine { } public function set fontWeight(value:String):void { + if (value == null) throwNonNull("fontWeight"); + if (value != FontWeight.NORMAL && value != FontWeight.BOLD) { + throwNotAccepted("fontWeight"); + } + this._fontWeight = value; } @@ -47,6 +52,11 @@ package flash.text.engine { } public function set fontPosture(value:String):void { + if (value == null) throwNonNull("fontPosture"); + if (value != FontPosture.NORMAL && value != FontPosture.ITALIC) { + throwNotAccepted("fontPosture"); + } + this._fontPosture = value; } @@ -55,6 +65,11 @@ package flash.text.engine { } public function set fontLookup(value:String):void { + if (value == null) throwNonNull("fontLookup"); + if (value != FontLookup.DEVICE && value != FontLookup.EMBEDDED_CFF) { + throwNotAccepted("fontLookup"); + } + this._fontLookup = value; } @@ -63,6 +78,11 @@ package flash.text.engine { } public function set renderingMode(value:String):void { + if (value == null) throwNonNull("renderingMode"); + if (value != RenderingMode.NORMAL && value != RenderingMode.CFF) { + throwNotAccepted("renderingMode"); + } + this._renderingMode = value; } @@ -71,6 +91,11 @@ package flash.text.engine { } public function set cffHinting(value:String):void { + if (value == null) throwNonNull("cffHinting"); + if (value != CFFHinting.NONE && value != CFFHinting.HORIZONTAL_STEM) { + throwNotAccepted("cffHinting"); + } + this._cffHinting = value; } @@ -79,5 +104,12 @@ package flash.text.engine { return false; } + private static function throwNonNull(name: String) { + throw new TypeError("Error #2007: Parameter " + name + " must be non-null.", 2007); + } + + private static function throwNotAccepted(name: String) { + throw new ArgumentError("Error #2008: Parameter " + name + " must be one of the accepted values.", 2008); + } } } diff --git a/tests/tests/swfs/avm2/text_engine_fontdescription/Test.as b/tests/tests/swfs/avm2/text_engine_fontdescription/Test.as new file mode 100644 index 000000000000..b0e2d00ad05d --- /dev/null +++ b/tests/tests/swfs/avm2/text_engine_fontdescription/Test.as @@ -0,0 +1,52 @@ +package { + import flash.display.Sprite; + import flash.text.engine.*; + + public class Test extends Sprite { + public function Test():void { + var font = new FontDescription(); + + var properties = ["cffHinting", "fontLookup", "fontName", "fontPosture", "fontWeight", "renderingMode"]; + for each (var prop in properties) { + trace("// FontDescription::" + prop) + + try { + font[prop] = null; + } catch (e) { + trace(e); + } + + try { + font[prop] = ""; + } catch (e) { + trace(e); + } + } + + font.cffHinting = CFFHinting.NONE; + trace("// cffHinting: " + font.cffHinting); + font.cffHinting = CFFHinting.HORIZONTAL_STEM; + trace("// cffHinting: " + font.cffHinting); + + font.fontLookup = FontLookup.DEVICE; + trace("// fontLookup: " + font.fontLookup); + font.fontLookup = FontLookup.EMBEDDED_CFF; + trace("// fontLookup: " + font.fontLookup); + + font.fontPosture = FontPosture.NORMAL; + trace("// fontPosture: " + font.fontPosture); + font.fontPosture = FontPosture.ITALIC; + trace("// fontPosture: " + font.fontPosture); + + font.fontWeight = FontWeight.NORMAL; + trace("// fontWeight: " + font.fontWeight); + font.fontWeight = FontWeight.BOLD; + trace("// fontWeight: " + font.fontWeight); + + font.renderingMode = RenderingMode.NORMAL; + trace("// renderingMode: " + font.renderingMode); + font.renderingMode = RenderingMode.CFF; + trace("// renderingMode: " + font.renderingMode); + } + } +} \ No newline at end of file diff --git a/tests/tests/swfs/avm2/text_engine_fontdescription/output.txt b/tests/tests/swfs/avm2/text_engine_fontdescription/output.txt new file mode 100644 index 000000000000..8ff297131bcb --- /dev/null +++ b/tests/tests/swfs/avm2/text_engine_fontdescription/output.txt @@ -0,0 +1,27 @@ +// FontDescription::cffHinting +TypeError: Error #2007: Parameter cffHinting must be non-null. +ArgumentError: Error #2008: Parameter cffHinting must be one of the accepted values. +// FontDescription::fontLookup +TypeError: Error #2007: Parameter fontLookup must be non-null. +ArgumentError: Error #2008: Parameter fontLookup must be one of the accepted values. +// FontDescription::fontName +TypeError: Error #2007: Parameter fontName must be non-null. +// FontDescription::fontPosture +TypeError: Error #2007: Parameter fontPosture must be non-null. +ArgumentError: Error #2008: Parameter fontPosture must be one of the accepted values. +// FontDescription::fontWeight +TypeError: Error #2007: Parameter fontWeight must be non-null. +ArgumentError: Error #2008: Parameter fontWeight must be one of the accepted values. +// FontDescription::renderingMode +TypeError: Error #2007: Parameter renderingMode must be non-null. +ArgumentError: Error #2008: Parameter renderingMode must be one of the accepted values. +// cffHinting: none +// cffHinting: horizontalStem +// fontLookup: device +// fontLookup: embeddedCFF +// fontPosture: normal +// fontPosture: italic +// fontWeight: normal +// fontWeight: bold +// renderingMode: normal +// renderingMode: cff diff --git a/tests/tests/swfs/avm2/text_engine_fontdescription/test.swf b/tests/tests/swfs/avm2/text_engine_fontdesc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Dyn9$>Fg+=Jk$8b>)3GxAJC=#F0SbK@Ww>kDvSkQo$23p|(p;`}_q zN4Rd5scRuUq=!|~oq|++k4}PQru%RN;F;_2tPhL2s7KXUR|5D3^XRcaJ=cea0KR!0 zp7-In9@i6UvU?lgo4z_3sPFXQ6u=AD;k!PZ*3+OK?k)m++gA?<>U({71mN6tIPb%w z`Y5Q!x-!7;`RcJit@Pmxz{}U+!eb8pAt2#9{06_pNZ`lW=uEJ|nnY~CIGCK`nF8Yy zqNp~b&nUGU`VFNvtIsMmNtcw`oIa=2ruAw6@fn)&U(G2{@Gx%TNdKqlWB6VA7bWhP EF{{DJVE_OC literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/text_engine_fontdescription/test.toml b/tests/tests/swfs/avm2/text_engine_fontdescription/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm2/text_engine_fontdescription/test.toml @@ -0,0 +1 @@ +num_frames = 1