Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 589287b

Browse filesBrowse files
skomskijasnell
authored andcommitted
src: convert BE-utf16-string to LE before search
On Big Endian platforms v8 strings are need to converted to Little Endian before searching in utf16le buffer Fixes: #3283 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Michael Dawson <mhdawson@ca.ibm.com> PR-URL: #3295
1 parent 2314378 commit 589287b
Copy full SHA for 589287b

File tree

Expand file treeCollapse file tree

1 file changed

+21
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-5
lines changed
Open diff view settings
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+21-5Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,27 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
842842
return args.GetReturnValue().Set(-1);
843843
}
844844

845-
result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
846-
haystack_length / 2,
847-
reinterpret_cast<const uint16_t*>(*needle_value),
848-
needle_value.length(),
849-
offset / 2);
845+
if (IsBigEndian()) {
846+
StringBytes::InlineDecoder decoder;
847+
decoder.Decode(Environment::GetCurrent(args), needle, args[3], UCS2);
848+
const uint16_t* decoded_string =
849+
reinterpret_cast<const uint16_t*>(decoder.out());
850+
851+
if (decoded_string == nullptr)
852+
return args.GetReturnValue().Set(-1);
853+
854+
result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
855+
haystack_length / 2,
856+
decoded_string,
857+
decoder.size() / 2,
858+
offset / 2);
859+
} else {
860+
result = SearchString(reinterpret_cast<const uint16_t*>(haystack),
861+
haystack_length / 2,
862+
reinterpret_cast<const uint16_t*>(*needle_value),
863+
needle_value.length(),
864+
offset / 2);
865+
}
850866
result *= 2;
851867
} else if (enc == UTF8) {
852868
String::Utf8Value needle_value(needle);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.