Fix multi-byte UTF-8 decoding in Executable stream handling#5510
Open
Fix multi-byte UTF-8 decoding in Executable stream handling#5510
Conversation
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix incorrect decoding of multi-byte characters in executable
Fix multi-byte UTF-8 decoding in Executable stream handling
Dec 18, 2025
dmichon-msft
approved these changes
Jan 2, 2026
Contributor
dmichon-msft
left a comment
There was a problem hiding this comment.
@copilot This change needs a patch changefile for node-core-library.
Member
|
@copilot - Generate a changefile documenting this change. It should be a patch bump. |
Co-authored-by: iclanton <5010588+iclanton@users.noreply.github.com>
Contributor
Author
D4N14L
approved these changes
Jan 7, 2026
| for (let i = 0; i < encoded.length; i++) { | ||
| process.stdout.write(encoded.subarray(i, i + 1)); | ||
| // Small delay to ensure each byte is in a separate chunk | ||
| await setTimeout(1); |
Contributor
There was a problem hiding this comment.
Is it possible to remove this timeout by reducing the chunk size to just one byte?
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.
Fix multi-byte character decoding in Executable.waitForExitAsync
waitForExitAsyncto set encoding on stdout/stderr streamsgetProcessInfoByIdAsyncto set encoding on stdout streamSummary
This PR fixes an issue where
Executable.waitForExitAsyncandgetProcessInfoByIdAsyncincorrectly decoded multi-byte UTF-8 characters when they were split across chunk boundaries from stdout and stderr streams.Root Cause
Calling
chunk.toString(encoding)on individual buffer chunks produces invalid characters when multi-byte UTF-8 sequences are split across chunk boundaries.Solution
Set the stream encoding explicitly using
stream.setEncoding(encoding)before attaching data handlers. When encoding is set on a stream, Node.js automatically uses aStringDecoderinternally which maintains state across chunks and properly handles character boundaries.Changes Made
waitForExitAsync: Set encoding on stdout/stderr streams before attaching handlers (when encoding is not 'buffer')getProcessInfoByIdAsync: Set encoding to 'utf8' on stdout streamTesting
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.