Repository navigation
Conversation
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
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.stringifyof a flat string of 134,217,726 two-byte or 268,435,451 one-byte chars kills the process on v26.13.0 withFATAL ERROR: Zone Allocation failed(nodejs#66489). the fast path reserves 8x the string length in one zone allocation before writing anything, andZone::Expandcalls fatal OOM overINT_MAXbytes. the property key path does the sameV8 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::kMaxLengthchars the fast path returnsSLOW_PATHand the slow stringifier produces the result or theRangeError. this is that commit cherry-picked onto 14.6.202.34, it applies with line offsets only, plus a pummel testofficial v26.13.0 linux x64: abort, exit 134. this branch:
134217730in 1.6s, andJSON.stringify(JSON.stringify('"'.repeat(149999999)))throwsRangeError: Invalid string lengthinstead of aborting. tradeoff is that flat strings over ~67M chars now always take the slow pathsame change for nodejs/node
mainandv26.x-staging: