This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Buffer issues with external two bytes string #8683
Labels
Comments
Interesting variation: var str = 'ABCD';
var buf = new Buffer(str);
console.log(buf.toString('hex')); // 41424344
externalizeString(str, true); // force two bytes string
var extbuf = new Buffer(str);
console.log(extbuf.toString('hex')); // 41004200
var buf = new Buffer('ABCD');
console.log(buf.toString('hex')); // 41004200 Although second |
This line causes the error : https://github.com/joyent/node/blob/master/src/string_bytes.cc#L331 Probably |
Also this line should return doubled length: https://github.com/joyent/node/blob/master/src/string_bytes.cc#L285 |
Closed
ghostoy
pushed a commit
to ghostoy/node
that referenced
this issue
Nov 20, 2014
bnoordhuis
added a commit
to bnoordhuis/io.js
that referenced
this issue
Mar 5, 2015
StringBytes::Write() did a plain memcpy() when is_extern is true but that's wrong when the source is a two-byte string and the destination a one-byte or UTF-8 string. The impact is limited to strings > 1,031,913 bytes because those are normally the only strings that are externalized, although the use of the 'externalize strings' extension (--expose_externalize_string) can also trigger it. This commit also cleans up the bytes versus characters confusion in StringBytes::Write() because that was closely intertwined with the UCS-2 encoding regression. One wasn't fixable without the other. Fixes: nodejs#1024 Fixes: nodejs/node-v0.x-archive#8683 PR-URL: nodejs#1042 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
richardlau
pushed a commit
to ibmruntimes/node
that referenced
this issue
Jan 21, 2017
Part of nodejs#8683, increase coverage of the internal state machine of streams. PR-URL: nodejs/node#10249 See: nodejs/node#8683 See: nodejs/node#10230 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
gibfahn
pushed a commit
to ibmruntimes/node
that referenced
this issue
Feb 22, 2017
Part of nodejs#8683, increase coverage of the internal state machine of streams. PR-URL: nodejs/node#10249 See: nodejs/node#8683 See: nodejs/node#10230 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
gibfahn
pushed a commit
to ibmruntimes/node
that referenced
this issue
Feb 22, 2017
Part of nodejs#8683, increase coverage of the internal state machine of streams. PR-URL: nodejs/node#10249 See: nodejs/node#8683 See: nodejs/node#10230 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Node Buffer doesn't work correctly with two bytes external strings. Once passing such string to Buffer constructor, the content of the Buffer is just first half of the string in UCS2 encoding.
Steps to reproduce:
--expose_externalize_string
flagAs documented for
new Buffer(str, [encoding])
:Therefore the expected content of
extbuf
should also be encoded in UTF8 (i.e.41424344
in this case) for any JS string by default.This issue should be the root cause of an node-webkit issue nwjs/nw.js#2439
The text was updated successfully, but these errors were encountered: