fix: decode only the viewed bytes of Uint8Array log data#772
Merged
taeold merged 1 commit intoJun 24, 2026
Merged
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
When execution-id logging is enabled, stdout/stderr writes are intercepted and re-decoded to attach execution context. The Uint8Array branch decoded `data.buffer`, which is the entire backing ArrayBuffer and ignores the view's `byteOffset`/`byteLength`. Node.js allocates most Buffers from a shared internal pool, so a Buffer written to stdout is frequently a view with a non-zero byteOffset into a much larger ArrayBuffer. Decoding `data.buffer` therefore captured unrelated pool bytes surrounding the real message, producing corrupted log output (e.g. logging the whole 8 KiB pool instead of "hello world"). Decode `Buffer.from(data.buffer, data.byteOffset, data.byteLength)` so only the bytes the view spans are read. Added a regression test that logs through a pooled, non-zero-offset view.
616878f to
2b52ffd
Compare
Contributor
|
Huh interesting. Thanks for the contribution! |
taeold
approved these changes
Jun 24, 2026
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
When execution-id logging is enabled, the framework intercepts
process.stdout/process.stderrwrites and re-decodes the data to attach execution context (src/logger.ts). TheUint8Arraybranch decodeddata.buffer:data.bufferis the entire backingArrayBufferand ignores the view'sbyteOffset/byteLength. Node.js allocates mostBuffers from a shared internal pool, so aBufferwritten to stdout is frequently a view with a non-zerobyteOffsetinto a much largerArrayBuffer. As a result, decodingdata.buffercaptures unrelated pool bytes surrounding the real message and produces corrupted log output.Reproduction
In practice this means a user function that does
process.stdout.write(Buffer.from('...'))(or logs via any library that emitsBuffers) gets garbled logs whenever execution-id support is on.Fix
Decode only the bytes the view spans:
Why the existing test didn't catch it
The
uint8arraytest usesnew Uint8Array(Buffer.from(sampleText)), which copies into a fresh, exactly-sizedArrayBufferwithbyteOffset === 0andbyteLength === buffer.byteLength— the one case where readingdata.bufferhappens to be correct.Testing
107 passing.🤖 Generated with Claude Code