Conversation
`JSON.parse(s)` lowered the operand with `unbox_to_i64`, which extracts the
raw NaN-boxed bits. For a heap string that's the `StringHeader*` (fine), but
for an SSO short string it's the INLINE character bytes — handed to
`js_json_parse`, which dereferences them as a `*StringHeader` and reads
`byte_len` off a garbage address → SIGSEGV.
So any short, runtime-built string crashed: `JSON.parse('e' + 'n')`,
`JSON.parse('enabled'.slice(0,2))`, `JSON.parse(String(1))`, etc. Heap strings
(string literals, large concatenations) happened to work, which is why it hid
until a real workload parsed many short values — e.g. @perryts/mysql decodes a
JSON column and the consumer re-`JSON.parse`s the short results, segfaulting a
whole HTTP service.
Lower both the generic and typed (`js_json_parse_typed_array`) arms through
`js_get_string_pointer_unified`, which returns the heap pointer for heap
strings and materializes SSO / number receivers to the heap first. Verified:
`JSON.parse('e'+'n')` now throws a catchable SyntaxError instead of crashing;
short valid inputs (`'1'`, `'42'`, `'true'`) parse correctly.
proggeramlug
force-pushed
the
fix/json-parse-sso
branch
from
June 1, 2026 17:16
dccc5f2 to
33b8745
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSON.parse(<short runtime string>)segfaults. Minimal repro:Cause
The
JSON.parsecodegen (expr/instance_misc1.rs) lowered its operand withunbox_to_i64, which just extracts the raw NaN-boxed bits. For a heap string that's theStringHeader*(works); for an SSO short string the bits are the inline character bytes, handed tojs_json_parse, which dereferences them as a*StringHeaderand readsbyte_lenoff a garbage address (the fault address is literally the inline chars, e.g.0x…6e65="ne").Heap strings (string literals, large concatenations) happened to work, so it hid until a workload parsed many short runtime values. Found bringing the Skelpo CMS up on Perry:
@perryts/mysqldecodes a JSON column, the app re-JSON.parses the short results, and the whole HTTP service segfaults onGET /api/v1/settings.Fix
Lower both the generic and typed (
js_json_parse_typed_array)JSON.parsearms throughjs_get_string_pointer_unified— it returns the heap pointer for heap strings and materializes SSO / number receivers to the heap first (the same coercion already used at other string FFI call sites).Verified
JSON.parse('e'+'n')now throws a catchableSyntaxErrorinstead of crashing;'1'/'42'/'true'parse correctly. End-to-end: the CMS's/api/v1/settings(≈940 KB of JSON-column data) now returns 200 and matches Node, and a full 15-route Node-vs-Perry sweep is identical.