bellard / quickjs

Public repository of the QuickJS Javascript Engine.
https://bellard.org/quickjs
Other
7.99k stars 830 forks source link

Consider making JSON parser ECMA-404 compliant #250

Open devinus opened 3 months ago

devinus commented 3 months ago

Right now the JSON parser has an unconfigurable maximum nesting depth and will fail on input such as this with the unfriendly exception SyntaxError: stack overflow when trying to parse a JSON object that's too deeply nested.

Consider making the parser ECMA 404 compliant by either 1) allowing infinite nesting, 2) a configurable nesting depth, or 3) documentation about the default maximum nesting depth (I'm assuming this is currently architecture specific).

chqrlie commented 3 months ago

Hey @devinus,

Thank you for mentioning the new RFC and its requirements.

I have rewritten the JSON parser for the https://github.com/quickjs-ng/quickjs friendly fork. I shall merge this into this repository as well, once it is finalized there. The new parser is much stricter (to my dismay) and should be fully conformant, except for the excessive depth case. I will consider switching to a non recursive parser using an allocated stack to get rid of the nesting limit.

Regarding the JSON spec, I cannot help but mention my personal rant about this format: