diff --git a/test/parallel/test-buffer-tostring-rangeerror.js b/test/parallel/test-buffer-tostring-rangeerror.js index b34f4c61261..856ed84d21c 100644 --- a/test/parallel/test-buffer-tostring-rangeerror.js +++ b/test/parallel/test-buffer-tostring-rangeerror.js @@ -34,6 +34,12 @@ function test(getBuffer) { return; } } + // MAX_STRING_LENGTH counts UTF-16 units, not bytes. Uninitialized memory can + // hold multi-byte UTF-8 sequences, which decode to fewer units than they + // occupy bytes, and a single one of them is enough to bring the result down + // to MAX_STRING_LENGTH or less. ASCII bytes keep the decoded length equal to + // the buffer length. + buf.fill(0); assert.throws(() => { buf.toString('utf8'); }, message); }