forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes chakra-core#5699 - Converts recursive loop to iterative in MayH…
…aveSideEffectOnNode to avoid a stack overflow.
- Loading branch information
Showing
3 changed files
with
112 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// MayHaveSideEffectOnNode() was a recursive function that could recurse enough times to cause | ||
// an uncaught stack overflow.This was fixed by converting the recursive loop into an iterative | ||
// loop. | ||
// | ||
// An example of a program that caused the stack overflow is: | ||
// eval("var a;a>(" + Array(2 ** 15).fill(0).join(",") + ");"); | ||
// | ||
// MayHaveSideEffectOnNode() is originally called because the righthand side of the pNodeBin | ||
// ">" may overwrite the lefthand side of ">". The righthand side of pNodeBin is a deep tree | ||
// in which each pNode of the longest path is a pNodeBin(",").Since children of the original | ||
// pNodeBin -> right are pNodeBins themselves, MayHaveSideEffectOnNode() must check all of | ||
// their children as well.MayHaveSideEffectOnNode's original implementation was recursive and | ||
// thus the stack would overflow while recursing through the path of pNodeBins. | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
var tests = [ | ||
{ | ||
name: "MayHaveSideEffectOnNode() should not cause a stack overflow nor should fail to \ | ||
terminate", | ||
body: function () { | ||
eval("var a;a>(" + Array(2 ** 15).fill(0).join(",") + ");"); | ||
eval("var a;a===(" + Array(2 ** 15).fill(0).join(",") + ");"); | ||
} | ||
} | ||
] | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters