string_decoder: throw ERR_STRING_TOO_LONG for UTF-8

String::NewFromUtf8 doesn't generate an exception in V8 when the string
is too long but is guaranteed to return an empty MaybeLocal only in
that case. Generate a Node.js exception when it happens.

Fixes: https://github.com/nodejs/node/issues/35676

PR-URL: https://github.com/nodejs/node/pull/36661
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Michaël Zasso authored and Danielle Adams committed 2021-01-12 07:10:25 -05:00
1 parent d5e1b82125
commit d2b9e7cb01
2 files changed
+15 -1

No files matched your search

+7
View File
@@ -201,6 +201,13 @@ assert.throws(
}
);
assert.throws(
() => new StringDecoder().write(Buffer.alloc(0x1fffffe8 + 1).fill('a')),
{
code: 'ERR_STRING_TOO_LONG',
}
);
// Test verifies that StringDecoder will correctly decode the given input
// buffer with the given encoding to the expected output. It will attempt all
// possible ways to write() the input buffer, see writeSequences(). The