From 1534112c8b9f16eb70b0441acae8c1915946f9ed Mon Sep 17 00:00:00 2001 From: Ray Wang Date: Sun, 26 Sep 2021 17:22:25 +0800 Subject: [PATCH 1/2] src: throw error instead of assertion --- src/node_buffer.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 0546e7a53fae90..48df1323ca7215 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -494,7 +494,12 @@ MaybeLocal New(Environment* env, size_t length) { if (length > 0) { CHECK_NOT_NULL(data); - CHECK(length <= kMaxLength); + // V8 currently only allows a maximum Typed Array index of max Smi. + if (length > kMaxLength) { + Isolate* isolate(env->isolate()); + isolate->ThrowException(ERR_BUFFER_TOO_LARGE(isolate)); + return Local(); + } } auto free_callback = [](char* data, void* hint) { free(data); }; From 2cb365103e033a48720651984c48a8dff8929c6f Mon Sep 17 00:00:00 2001 From: Ray Wang Date: Tue, 5 Oct 2021 08:50:50 +0800 Subject: [PATCH 2/2] doc: describe buffer limit of v8.serialize --- doc/api/v8.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/api/v8.md b/doc/api/v8.md index f94231451a5982..87b1790a6536ca 100644 --- a/doc/api/v8.md +++ b/doc/api/v8.md @@ -323,6 +323,10 @@ added: v8.0.0 Uses a [`DefaultSerializer`][] to serialize `value` into a buffer. +[`ERR_BUFFER_TOO_LARGE`][] will be thrown when trying to +serialize a huge object which requires buffer +larger than [`buffer.constants.MAX_LENGTH`][]. + ### `v8.deserialize(buffer)`