buffer: fix needle length misestimation for UCS2 · nodejs/node@a550ddb · GitHub
Skip to content

Commit a550ddb

Browse files
addaleaxevanlucas
authored andcommitted
buffer: fix needle length misestimation for UCS2
Use `StringBytes::Size` to determine the needle string length instead of assuming latin-1 or UTF-8. Previously, `Buffer.indexOf` could fail with an assertion failure when the needle's byte length, but not its character count, exceeded the haystack's byte length. PR-URL: #6511 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 6fc20c5 commit a550ddb

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/node_buffer.cc

Lines changed: 2 additions & 2 deletions

test/parallel/test-buffer-indexof.js

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)