n-api: add check for large strings · nodejs/node@5f469a2 · GitHub
Skip to content

Commit 5f469a2

Browse files
mhdawsonMylesBorins
authored andcommitted
n-api: add check for large strings
n-api uses size_t for the size of strings when specifying string lengths. V8 only supports a size of int. Add a check so that an error will be returned if the user passes in a string with a size larger than will fit into an int. PR-URL: #15611 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 3f2ea53 commit 5f469a2

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/node_api.cc

Lines changed: 5 additions & 1 deletion

test/addons-napi/test_string/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ assert.strictEqual(test_string.TestUtf8Insufficient(str6), str6.slice(0, 1));
6969
assert.strictEqual(test_string.TestUtf16Insufficient(str6), str6.slice(0, 3));
7070
assert.strictEqual(test_string.Utf16Length(str6), 5);
7171
assert.strictEqual(test_string.Utf8Length(str6), 14);
72+
73+
assert.throws(() => {
74+
test_string.TestLargeUtf8();
75+
}, /^Error: Invalid argument$/);

test/addons-napi/test_string/test_string.c

Lines changed: 15 additions & 0 deletions

0 commit comments

Comments
 (0)