Open Bug 2034840 Opened 1 month ago Updated 1 day ago

"InternalError: too much recursion" on deep ternary chains

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

People

(Reporter: skyschub, Unassigned)

References

(Blocks 1 open bug, )

Details

As part of investigations into the backgrounds of bug 2033215, Microsoft let us know about a difference in browser behavior on deep-nested ternary operator chains. It appears that Firefox throws a

InternalError: too much recursion

at ~5k nested operations, while V8 has no issues with 100k. A very helpful MS engineer (thank you!!) provided a repo with instructions and more details at https://github.com/guru-irl/firefox-ternary-parse-recursion

While no human would ever hand-write code like that, the code in question was created by oxc, which is increasing in popularity, and the problematic code in question was part of a chunk-id-to-filename map function as per the repo, so I can totally imagine other web apps eventually running into the same limit.

We should figure out if we can get closer to V8's behavior here in order to avoid future surprises.

Flags: needinfo?(arai.unmht)

This needs modification in the following parts:

  • The recursion between GeneralParser::condExpr and GeneralParser::assignExpr
  • The recursion in ParseNodeVisitor, its subclasses, and TernaryNode::visit
  • The recursion between BytecodeEmitter::emitConditionalExpression and BytecodeEmitter::emitTree

We could use similar structure as if-else-if.

Blocks: sm-frontend
Severity: -- → S3
Flags: needinfo?(arai.unmht)
Priority: -- → P3

Safari throws an exception at a depth of 6325 for me.

I filed an issue against oxc to avoid introducing these problems: https://github.com/oxc-project/oxc/issues/21901

and guru-irl had previously put a PR up: https://github.com/oxc-project/oxc/pull/21841

You need to log in before you can comment on or make changes to this bug.