Skip to content

Commit 05e960e

Browse files
ChALkeRgurgunday
andauthored
Update src/string_bytes.cc
Co-authored-by: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent daabc98 commit 05e960e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/string_bytes.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
543543
// We know that we are non-ASCII (and are unlikely Latin1), use 2-byte
544544
// In the most likely case of valid UTF-8, we can use this fast impl
545545
size_t u16size = simdutf::utf16_length_from_utf8(buf, buflen);
546+
if (u16size > static_cast<size_t>(v8::String::kMaxLength)) {
547+
isolate->ThrowException(node::ERR_STRING_TOO_LONG(isolate));
548+
return MaybeLocal<Value>();
549+
}
546550
uint16_t* dst = node::UncheckedMalloc<uint16_t>(u16size);
547551
if (u16size != 0 && dst == nullptr) {
548552
isolate->ThrowException(node::ERR_MEMORY_ALLOCATION_FAILED(isolate));

0 commit comments

Comments
 (0)