-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
stream: fix UTF-8 character corruption in fast-utf8-stream #61745
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
Open
mcollina
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
mcollina:fix-utf8-stream-partial-write
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Fix releaseWritingBuf() to correctly handle partial writes that split multi-byte UTF-8 characters. The previous implementation incorrectly converted byte counts to character counts, causing: - 3-byte characters (CJK) to be silently dropped - 4-byte characters (emoji) to leave lone surrogates in the buffer The fix backs up from the byte position to find a valid UTF-8 character boundary by checking for continuation bytes (pattern 10xxxxxx), then decodes the properly-aligned bytes to get the correct character count. Also fixes a typo where this._asyncDrainScheduled was used instead of the private field this.#asyncDrainScheduled. Fixes: nodejs#61744
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61745 +/- ##
==========================================
- Coverage 89.74% 89.74% -0.01%
==========================================
Files 674 675 +1
Lines 204360 204537 +177
Branches 39265 39308 +43
==========================================
+ Hits 183412 183569 +157
- Misses 13251 13257 +6
- Partials 7697 7711 +14
🚀 New features to boost your workflow:
|
anonrig
approved these changes
Feb 9, 2026
jasnell
approved these changes
Feb 9, 2026
cjihrig
approved these changes
Feb 10, 2026
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.
Summary
Fix
releaseWritingBuf()to correctly handle partial writes that split multi-byte UTF-8 characters.The previous implementation incorrectly converted byte counts to character counts by using:
When
nbytes cuts through a multi-byte character, the incomplete UTF-8 sequence becomes U+FFFD (replacement character) via.toString(), which has a different.lengththan the original character. This caused:The fix backs up from the byte position to find a valid UTF-8 character boundary by checking for continuation bytes (pattern
10xxxxxx), then decodes the properly-aligned bytes to get the correct character count.Also fixes a typo where
this._asyncDrainScheduledwas used instead of the private fieldthis.#asyncDrainScheduled.Fixes: #61744