summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrevor Norris <trev.norris@gmail.com>2016-01-21 14:00:59 -0700
committerTrevor Norris <trev.norris@gmail.com>2016-01-22 11:32:43 -0700
commit54cd2e1e5e2f67886a78b13dc17473e84b938d16 (patch)
tree626dffcb2e8f62d9ce208b49b36eba44472197c6 /src
parent7240ad44413a096f6611afbcf356acedd8867fa7 (diff)
downloadnode-new-54cd2e1e5e2f67886a78b13dc17473e84b938d16.tar.gz
buffer: properly retrieve binary length of needle
If the needle contains an extended latin-1 character then using String::Utf8Length() will be too large and the search will return early. Instead use String::Length() when encoding is BINARY. PR-URL: https://github.com/nodejs/node/pull/4803 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_buffer.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index dca75a817b..988e41dbc9 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -849,7 +849,9 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
Local<String> needle = args[1].As<String>();
const char* haystack = ts_obj_data;
const size_t haystack_length = ts_obj_length;
- const size_t needle_length = needle->Utf8Length();
+ // Extended latin-1 characters are 2 bytes in Utf8.
+ const size_t needle_length =
+ enc == BINARY ? needle->Length() : needle->Utf8Length();
if (needle_length == 0 || haystack_length == 0) {