src: fix ucs-2 buffer encoding regression
authorBen Noordhuis <info@bnoordhuis.nl>
Tue, 3 Mar 2015 14:44:54 +0000 (15:44 +0100)
committerBen Noordhuis <info@bnoordhuis.nl>
Thu, 5 Mar 2015 19:44:19 +0000 (20:44 +0100)
commit1640dedb3b2a8d6e54ba7b22290d86d5984768be
tree22c1954f8abfab32dcebb508efcdcaa282baed25
parent2eda2d609658826c559fca1944b0e6aafb9d1344
src: fix ucs-2 buffer encoding regression

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: https://github.com/iojs/io.js/issues/1024
Fixes: https://github.com/joyent/node/issues/8683
PR-URL: https://github.com/iojs/io.js/pull/1042
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
src/node_buffer.cc
src/string_bytes.cc
test/parallel/test-stringbytes-external.js