stream: fix UTF-8 character corruption in fast-utf8-stream#61745
Open
mcollina wants to merge 1 commit intonodejs:mainfrom
Open
stream: fix UTF-8 character corruption in fast-utf8-stream#61745mcollina wants to merge 1 commit intonodejs:mainfrom
mcollina wants to merge 1 commit intonodejs:mainfrom
Conversation
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.64% 89.65% +0.01%
==========================================
Files 676 676
Lines 206249 206338 +89
Branches 39518 39526 +8
==========================================
+ Hits 184892 184999 +107
+ Misses 13479 13468 -11
+ Partials 7878 7871 -7
🚀 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
Member
Author
|
Manual CI: https://ci.nodejs.org/job/node-test-pull-request/71336/ (no idea why request-ci did not work here) |
Member
Author
|
@nodejs/build can someone help to see why CI is not starting? |
ShogunPanda
approved these changes
Feb 26, 2026
Collaborator
Commit Queue failed- Loading data for nodejs/node/pull/61745 ✔ Done loading data for nodejs/node/pull/61745 ----------------------------------- PR info ------------------------------------ Title stream: fix UTF-8 character corruption in fast-utf8-stream (#61745) Author Matteo Collina <[email protected]> (@mcollina) Branch mcollina:fix-utf8-stream-partial-write -> nodejs:main Labels stream, needs-ci, commit-queue-squash Commits 1 - stream: fix UTF-8 character corruption in fast-utf8-stream Committers 1 - Matteo Collina <[email protected]> PR-URL: https://github.com/nodejs/node/pull/61745 Fixes: https://github.com/nodejs/node/issues/61744 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/61745 Fixes: https://github.com/nodejs/node/issues/61744 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Sun, 08 Feb 2026 20:39:59 GMT ✔ Approvals: 4 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/61745#pullrequestreview-3770760306 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/61745#pullrequestreview-3774539778 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/61745#pullrequestreview-3778727542 ✔ - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/61745#pullrequestreview-3859183492 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-02-13T22:03:07Z: https://ci.nodejs.org/job/node-test-pull-request/71336/ - Querying data for job/node-test-pull-request/71336/ ✔ Build data downloaded ✘ 1 failure(s) on the last Jenkins CI run -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/22433955375 |
Contributor
|
|
Member
Author
|
Should I open a fresh PR? |
Member
|
Rebasing and force pushing might fix the issue |
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
4f5cf65 to
4a8f0e0
Compare
ShogunPanda
approved these changes
Mar 4, 2026
Collaborator
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.
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