Skip to content

Commit bcb97d1

Browse files
committed
[MERGE #6127 @boingoing] OS#18260560 - ASSERTION : scope at GetEnclosingFunc
Merge pull request #6127 from boingoing:bug_OS18260560 Named function expression with nested-function declared in default arguments containing a with statement referencing the parent function expression by name results in a null dereference of the enclosing scope. ```javascript (function foo(a = function bar() { with ({}) { foo; } }()) {})(); ``` We try and look at the param scope and body scope but we don't check the function expression scope in `ByteCodeGenerator::CheckDeferParseHasMaybeEscapedNestedFunc`. Simple fix is to check function expression scope if param and body scope are nullptr. Fixes: https://microsoft.visualstudio.com/OS/_workitems/edit/18260560 Found vis oss-fuzz
2 parents 68d19b7 + 371209c commit bcb97d1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,10 @@ void ByteCodeGenerator::CheckDeferParseHasMaybeEscapedNestedFunc()
20962096
else
20972097
{
20982098
// We have to wait until it is parsed before we populate the stack nested func parent.
2099-
FuncInfo * parentFunc = top->GetParamScope() ? top->GetParamScope()->GetEnclosingFunc() : top->GetBodyScope()->GetEnclosingFunc();
2099+
Scope * enclosingScope = top->GetParamScope() ? top->GetParamScope() :
2100+
top->GetBodyScope() ? top->GetBodyScope() :
2101+
top->GetFuncExprScope();
2102+
FuncInfo * parentFunc = enclosingScope->GetEnclosingFunc();
21002103
if (!parentFunc->IsGlobalFunction())
21012104
{
21022105
Assert(parentFunc->byteCodeFunction != rootFuncBody);

test/Bugs/bug_OS18260560.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
(function foo(a = function bar() {
7+
with ({}) {
8+
foo;
9+
}
10+
}()) {})();
11+
12+
console.log("pass");

test/Bugs/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,10 @@
570570
<compile-flags>-maxinterpretcount:1 -maxsimplejitruncount:1 -MinMemOpCount:0 -werexceptionsupport -bgjit- -loopinterpretcount:1</compile-flags>
571571
</default>
572572
</test>
573+
<test>
574+
<default>
575+
<files>bug_OS18260560.js</files>
576+
<compile-flags>-force:deferparse</compile-flags>
577+
</default>
578+
</test>
573579
</regress-exe>

0 commit comments

Comments
 (0)