diff --git a/src/node_buffer.h b/src/node_buffer.h index 606a6f5caa3..76d57d8384e 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -29,7 +29,9 @@ namespace node { namespace Buffer { -static const size_t kMaxLength = v8::TypedArray::kMaxLength; +static constexpr size_t kMaxLength = + v8::TypedArray::kMaxLength < 0x10000000000ull ? v8::Uint8Array::kMaxLength + : 0x10000000000ull; typedef void (*FreeCallback)(char* data, void* hint); diff --git a/src/node_errors.h b/src/node_errors.h index 0f4a2d0cc6e..6fa8b7230ff 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -5,6 +5,7 @@ #include "debug_utils-inl.h" #include "env.h" +#include "node_buffer.h" #include "v8.h" // Use ostringstream to print exact-width integer types @@ -210,9 +211,10 @@ inline void THROW_ERR_SCRIPT_EXECUTION_TIMEOUT(Environment* env, inline v8::Local ERR_BUFFER_TOO_LARGE(v8::Isolate* isolate) { char message[128]; - snprintf(message, sizeof(message), - "Cannot create a Buffer larger than 0x%zx bytes", - v8::TypedArray::kMaxLength); + snprintf(message, + sizeof(message), + "Cannot create a Buffer larger than 0x%zx bytes", + Buffer::kMaxLength); return ERR_BUFFER_TOO_LARGE(isolate, message); }