src: fix two encodeInto() bugs that reject input that fits - #65998
Open
agape1225 wants to merge 1 commit into
Open
src: fix two encodeInto() bugs that reject input that fits#65998agape1225 wants to merge 1 commit into
agape1225 wants to merge 1 commit into
Conversation
TextEncoder.encodeInto() could report that a code point does not fit in the destination Uint8Array even when it does. 1. simpleUtfEncodingLength() used 0x400 as the boundary between 2-byte and 3-byte UTF-8 encodings, but the correct boundary is 0x800: code points in [0x80, 0x800) need 2 bytes in UTF-8, and only code points >= 0x800 need 3. 2. The same function is called with a raw `char` from the Latin1 (one-byte string) code path. `char` is signed on some platforms, so a byte >= 0x80 gets sign-extended to a large uint16_t value instead of the intended code point, which also made encodeInto() behave differently for the same prefix depending on whether the rest of the source string forced V8 to represent it as one-byte (Latin1) or two-byte (UTF-16) internally. Fixes: nodejs#65994 Signed-off-by: agape1225 <49804691+agape1225@users.noreply.github.com>
agape1225
force-pushed
the
encoding-fix-encodeinto-underfill
branch
from
September 12, 2026 07:00
afc9088 to
4e69ac9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TextEncoder.encodeInto() could report that a code point does not fit in the destination Uint8Array even when it does.
simpleUtfEncodingLength() used 0x400 as the boundary between 2-byte and 3-byte UTF-8 encodings, but the correct boundary is 0x800: code points in [0x80, 0x800) need 2 bytes in UTF-8, and only code points
The same function is called with a raw
charfrom the Latin1 (one-byte string) code path.charis signed on some platforms, so a byte >= 0x80 gets sign-extended to a large uint16_t value instead of the intended code point, which also made encodeInto() behave differently for the same prefix depending on whether the rest of the source string forced V8 to represent it as one-byte (Latin1) or two-byte (UTF-16) internally.Fixes: #65994