Skip to content

Commit 81a01b1

Browse files
author
Suwei Chen
committed
OS4927797: TypeofElem fastpath mishandling out-of-range scenario
Fastpaths for opcode 'TypeofElem' mistakenly return 'number' for certain out-of-range situations. Fix by adding check 'undefined' for return values in the fastpaths.
1 parent 6a8c6df commit 81a01b1

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,8 +2458,11 @@ namespace Js
24582458
Var member;
24592459

24602460
// If the item is found in the array own body, then it is a number
2461-
if (JavascriptOperators::GetOwnItem(object, index, &member, scriptContext))
2461+
if (JavascriptOperators::GetOwnItem(object, index, &member, scriptContext)
2462+
&& !JavascriptOperators::IsUndefined(member))
2463+
{
24622464
return TRUE;
2465+
}
24632466
}
24642467
return FALSE;
24652468
}

test/typedarray/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,11 @@ Below test fails with difference in space. Investigate the cause and re-enable t
321321
<compile-flags>-mic:1 -off:simplejit -off:JITLoopBody -mmoc:0</compile-flags>
322322
</default>
323323
</test>
324+
<test>
325+
<default>
326+
<files>typedarray_bugfixes.js</files>
327+
<compile-flags>-Off:Deferparse -args summary -endargs</compile-flags>
328+
<tags>BugFix</tags>
329+
</default>
330+
</test>
324331
</regress-exe>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
var tests = [
9+
{
10+
name: "OS4927797: TypeofElem fastpath mishandling out-of-range scenario",
11+
body: function () {
12+
assert.areEqual("undefined", typeof new Int8Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Int8Array");
13+
assert.areEqual("undefined", typeof new Uint8Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Uint8Array");
14+
assert.areEqual("undefined", typeof new Uint8ClampedArray()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Uint8ClampedArray");
15+
assert.areEqual("undefined", typeof new Int16Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Int16Array");
16+
assert.areEqual("undefined", typeof new Uint16Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Uint16Array");
17+
assert.areEqual("undefined", typeof new Int32Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Int32Array");
18+
assert.areEqual("undefined", typeof new Uint32Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Uint32Array");
19+
assert.areEqual("undefined", typeof new Float32Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Float32Array");
20+
assert.areEqual("undefined", typeof new Float64Array()[NaN & 0XF], "TypeofElem should return 'undefined' for out-of-range situation in Float64Array");
21+
}
22+
},
23+
];
24+
25+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)