Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer.write incorrectly written one more byte in utf16le encoding #26422

Closed
hkjackey opened this issue Mar 4, 2019 · 3 comments
Closed

buffer.write incorrectly written one more byte in utf16le encoding #26422

hkjackey opened this issue Mar 4, 2019 · 3 comments
Labels
buffer Issues and PRs related to the buffer subsystem.

Comments

@hkjackey
Copy link

hkjackey commented Mar 4, 2019

Version: v11.10.1, v10.12.0
Platform: Windows 10 (64-bits)
Subsystem: buffer
File Encoding: UTF8

Please consider the following 3 lines of code:
let buf = Buffer.alloc(9);
buf.write('\ud842\udfb7', 1, 'utf16le');
console.log(buf); //<Buffer 00 42 d8 b7 df df 00 00 00>

In this example, only 4 bytes should be written.
However, the last 'df' (the 5th byte) is incorrectly written when the offset is odd number (1,3,5,...)

@BridgeAR
Copy link
Member

BridgeAR commented Mar 4, 2019

Ping @addaleax (I know you recently fixed an issue with utf16le).

@addaleax addaleax added the buffer Issues and PRs related to the buffer subsystem. label Mar 4, 2019
addaleax added a commit to addaleax/node that referenced this issue Mar 4, 2019
Do not write one character too much before shifting the whole result
to the left when using UTF16-LE, possibly overwriting already-used
memory while doing so.

Fixes: nodejs#26422
@addaleax
Copy link
Member

addaleax commented Mar 4, 2019

Interesting, this has been broken ever since 68e53dd. See #26432 for a solution.

@hkjackey
Copy link
Author

hkjackey commented Mar 5, 2019

Thanks for handling it!

BridgeAR pushed a commit to BridgeAR/node that referenced this issue Mar 12, 2019
Do not write one character too much before shifting the whole result
to the left when using UTF16-LE, possibly overwriting already-used
memory while doing so.

Fixes: nodejs#26422

PR-URL: nodejs#26432
Fixes: nodejs#26422
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
BridgeAR pushed a commit that referenced this issue Mar 14, 2019
Do not write one character too much before shifting the whole result
to the left when using UTF16-LE, possibly overwriting already-used
memory while doing so.

Fixes: #26422

PR-URL: #26432
Fixes: #26422
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
BethGriggs pushed a commit that referenced this issue Apr 16, 2019
Do not write one character too much before shifting the whole result
to the left when using UTF16-LE, possibly overwriting already-used
memory while doing so.

Fixes: #26422

PR-URL: #26432
Fixes: #26422
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants