Skip to content

Commit 5ec0ca7

Browse files
committed
[MERGE #5395 @paolosevMSFT] OS#17614914 - SCCLiveness::ProcessStackSymUse lifetime nullptr deref
Merge pull request #5395 from paolosevMSFT:17614914 In bug 17614914 JIT is causing a bad code gen, but the root problem is that with a script like: ``` Object.prototype.length = undefined; var ary = new Array(); var func0 = function() { for (var _strvar2 in ary) { console.log(_strvar2); } }; func0(); ``` a built-in property like Array.length should not be enumerated even if it is defined in Object.prototype. This PR fixes this problem by ignoring the builtin properties in ForInObjectEnumerator::MoveAndGetNext().
2 parents e8e9baa + 89f80cb commit 5ec0ca7

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

lib/Runtime/Library/ForInObjectEnumerator.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ namespace Js
210210
return nullptr;
211211
}
212212

213+
RecyclableObject* previousObject = this->shadowData->currentObject;
214+
213215
RecyclableObject * object;
214216
if (!this->enumeratingPrototype)
215217
{
@@ -249,6 +251,21 @@ namespace Js
249251
}
250252
}
251253
while (true);
254+
255+
// Ignore special properties (ex: Array.length)
256+
if (previousObject != nullptr)
257+
{
258+
uint specialPropertyCount = previousObject->GetSpecialPropertyCount();
259+
if (specialPropertyCount > 0)
260+
{
261+
PropertyId const* specialPropertyIds = previousObject->GetSpecialPropertyIds();
262+
Assert(specialPropertyIds != nullptr);
263+
for (uint i = 0; i < specialPropertyCount; i++)
264+
{
265+
TestAndSetEnumerated(specialPropertyIds[i]);
266+
}
267+
}
268+
}
252269
}
253270
}
254271
}

test/Bugs/bug_OS17614914.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
Object.prototype.length = undefined;
7+
var ary = Array();
8+
ary.prop1 = 1;
9+
Object.defineProperty(ary, "prop2", {
10+
value: 1,
11+
enumerable: false
12+
});
13+
for (var prop in ary) {
14+
if (prop !== "prop1") {
15+
console.log(`Fail: ${prop} property should not show in for-in`);
16+
}
17+
}
18+
console.log("pass");

test/Bugs/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,9 @@
501501
<files>withSplitScope.js</files>
502502
</default>
503503
</test>
504+
<test>
505+
<default>
506+
<files>bug_OS17614914.js</files>
507+
</default>
508+
</test>
504509
</regress-exe>

0 commit comments

Comments
 (0)