Repository navigation
Commit 752ab90
committed
[JSC] Deeply nested destructuring pattern crashes bytecode generation
https://bugs.webkit.org/show_bug.cgi?id=322333
Reviewed by Yusuke Suzuki.
The parser guards its own recursion and accepts destructuring patterns
nested ~20k levels deep, but ArrayPatternNode::bindValue recurses into
nested patterns with no stack check. Each level costs about 1KB of
native stack for the iterator temporaries and try/finally machinery, so
a pattern several thousand levels deep overflows the stack before the
parser's limit is reached:
let [[[ /* 12000 levels */ z ]]] = []; // SIGSEGV
ObjectPatternNode::bindValue has the same unbounded recursion.
Add the isSafeToRecurse() check that emitNode() already performs to the
top of both bindValue implementations. On failure, bytecode generation
reports ParserError::OutOfMemory and the caller sees a catchable
RangeError, matching other engines.
Test: JSTests/stress/destructuring-pattern-deep-recursion.js
* JSTests/stress/destructuring-pattern-deep-recursion.js: Added.
(shouldThrowRangeError):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::ArrayPatternNode::bindValue const):
(JSC::ObjectPatternNode::bindValue const):
Canonical link: https://commits.webkit.org/319778@main1 parent 1330d57 commit 752ab90
2 files changed
Lines changed: 37 additions & 0 deletions
File tree
- JSTests/stress
- Source/JavaScriptCore/bytecompiler
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5811 | 5811 | | |
5812 | 5812 | | |
5813 | 5813 | | |
| 5814 | + | |
| 5815 | + | |
| 5816 | + | |
| 5817 | + | |
| 5818 | + | |
5814 | 5819 | | |
5815 | 5820 | | |
5816 | 5821 | | |
| |||
6000 | 6005 | | |
6001 | 6006 | | |
6002 | 6007 | | |
| 6008 | + | |
| 6009 | + | |
| 6010 | + | |
| 6011 | + | |
| 6012 | + | |
6003 | 6013 | | |
6004 | 6014 | | |
6005 | 6015 | | |
| |||
0 commit comments