Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Unified Diff: src/json-stringifier.cc

Issue 2069563002: [json] detect overflow sooner when serializing large sparse array. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: check string length upfront Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/string-builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-stringifier.cc
diff --git a/src/json-stringifier.cc b/src/json-stringifier.cc
index 51899a9c8bc765a4a7587416a4643ac19af0edab..10f157333c62aa254c0dac6c57b0951283cd7aad 100644
--- a/src/json-stringifier.cc
+++ b/src/json-stringifier.cc
@@ -476,6 +476,12 @@ JsonStringifier::Result JsonStringifier::SerializeJSArray(
JsonStringifier::Result JsonStringifier::SerializeArrayLikeSlow(
Handle<JSReceiver> object, uint32_t start, uint32_t length) {
+ // We need to write out at least two characters per array element.
+ static const int kMaxSerializableArrayLength = String::kMaxLength / 2;
+ if (length > kMaxSerializableArrayLength) {
+ isolate_->Throw(*isolate_->factory()->NewInvalidStringLengthError());
+ return EXCEPTION;
+ }
for (uint32_t i = start; i < length; i++) {
Separator(i == 0);
Handle<Object> element;
@@ -485,6 +491,8 @@ JsonStringifier::Result JsonStringifier::SerializeArrayLikeSlow(
Result result = SerializeElement(isolate_, element, i);
if (result == SUCCESS) continue;
if (result == UNCHANGED) {
+ // Detect overflow sooner for large sparse arrays.
+ if (builder_.HasOverflowed()) return EXCEPTION;
builder_.AppendCString("null");
} else {
return result;
« no previous file with comments | « no previous file | src/string-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698