Skip to content

deps: V8: cherry-pick 8a1da7c84be7 (JSON.stringify zone abort) - #11

Draft
maschwenk wants to merge 2 commits into
base-v26.13.0from
v8-json-stringify-zone-v26.13.0
Draft

maschwenk wants to merge 2 commits into
base-v26.13.0from
v8-json-stringify-zone-v26.13.0

Conversation

@maschwenk

Copy link
Copy Markdown
Owner

JSON.stringify of a flat string of 134,217,726 two-byte or 268,435,451 one-byte chars kills the process on v26.13.0 with FATAL ERROR: Zone Allocation failed (nodejs#66489). the fast path reserves 8x the string length in one zone allocation before writing anything, and Zone::Expand calls fatal OOM over INT_MAX bytes. the property key path does the same

V8 already fixed it in https://chromium-review.googlesource.com/c/v8/v8/+/8529766 (v8/v8@8a1da7c84be7, first in 15.7.76): when a reservation would be over String::kMaxLength chars the fast path returns SLOW_PATH and the slow stringifier produces the result or the RangeError. this is that commit cherry-picked onto 14.6.202.34, it applies with line offsets only, plus a pummel test

const s = JSON.stringify('€' + 'a'.repeat(134217723));
console.log(JSON.stringify(s).length);

official v26.13.0 linux x64: abort, exit 134. this branch: 134217730 in 1.6s, and JSON.stringify(JSON.stringify('"'.repeat(149999999))) throws RangeError: Invalid string length instead of aborting. tradeoff is that flat strings over ~67M chars now always take the slow path

same change for nodejs/node main and v26.x-staging:

Original commit message:

    [json] Stringify: Bailout to slow-path if a string could exceed max len

    For strings that might require escaping, we calculate a pessimistic max
    length. This allows us to avoid any bounds checks when writing to the
    buffer.
    However this pessimistic max length can be greater than the allowed
    string max length (and even greater than INT_MAX), which could cause
    zone allocation to fail.
    To avoid zone allocation failure, we fall-back to the slow path if the
    pessimistic max length exceeds the allowed string max length.

    Fixed: 568816246
    Change-Id: I496c34084bce56faad740ad4e139373d6d792552
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8529766
    Reviewed-by: Igor Sheludko <ishell@chromium.org>
    Commit-Queue: Patrick Thier <pthier@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#110411}

Refs: v8/v8@8a1da7c
Fixes: nodejs#66489
JSON.stringify() of a flat string of 134217726 two-byte or 268435451
one-byte characters aborted the process with "Zone Allocation failed".
Check that it returns the result, also for an object value and a
property key, and that a result over the maximum string length throws
a RangeError.

Refs: nodejs#66489
@maschwenk maschwenk added the coder-task-generated Opened by a coding agent label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coder-task-generated Opened by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant