fix(index): decode child stdout/stderr as one contiguous buffer - #605
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes UnRTF#convert() output corruption when UTF-8 multibyte sequences are split across stdout/stderr chunk boundaries by buffering raw bytes and decoding once at process close, which also reduces transient heap pressure during conversion.
Changes:
- Update
convert()to accumulatestdout/stderrasBuffer[]and decode once viaBuffer.concat(...).toString("utf8"). - Add unit tests that simulate chunk-boundary splits for 2-, 3-, and 4-byte UTF-8 characters to prevent regression.
- Minor test refactor to reuse
EventEmitter/Readableimports for child process mocks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/index.js |
Buffers child process output as contiguous bytes and decodes once to avoid UTF-8 boundary corruption. |
test/index.test.js |
Adds regression tests for UTF-8 chunk-boundary splits and tidies child_process mocking setup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fdawgs
force-pushed
the
fix/chunk-boundary
branch
from
July 18, 2026 06:29
15d54e9 to
aa5beb2
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.
Crazily I was just looking to reduce the transient heap size that would bloat during conversion but ended up finding a chunk boundary bug.
This PR updates
convert()to collect stdout/stderr chunks into Buffer arrays and decode once on close viaBuffer.concat().toString()instead of accumulating them withstdOut += data.The previous approach implicitly called
Buffer.prototype.toString()per chunk, which decoded each chunk independently. Multibyte UTF-8 sequences split across pipe chunk boundaries were replaced withU+FFFD, silently corrupting output.Decoding once over contiguous bytes fixes the boundary bug and lowers peak heap use during conversion by ~40-50% in benchmarks.
Checklist
npm test