Skip to content

Fix buffer corruption - #38

Merged
nex3 merged 2 commits into
sass:mainfrom
sass-contrib:fix-buffer-copy
Oct 26, 2026
Merged

nex3 merged 2 commits into
sass:mainfrom
sass-contrib:fix-buffer-copy

Conversation

@ntkme

@ntkme ntkme commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

The issue is that the underneath ArrayBuffer can sometimes be longer than the wrapping Buffer, which is a "view" on top of the ArrayBuffer. If we just do Buffer.from(message.data.buffer), it may get a new view with the extra bytes (all zeros) which ends up corrupting stdout/stderr streams.

The correct way to create a duplicate view is Buffer.from(message.data.buffer, message.data.byteOffset, message.data.length).

Honestly, from what I can see the only reason we are re-wrapping the buffer is to deal with the TypeScript inconsistency between Type 'Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>' and 'Buffer<ArrayBufferLike>'. From pure JS, passing message.data as is without re-wrapping works just fine.

@nex3 nex3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for digging into this and finding the fix!

Honestly, from what I can see the only reason we are re-wrapping the buffer is to deal with the TypeScript inconsistency between Type 'Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>' and 'Buffer<ArrayBufferLike>'. From pure JS, passing message.data as is without re-wrapping works just fine.

Right; since this is a user-facing API, I want to make sure that it's a consistent type, so the user doesn't have to deal with converting types (which as we can see has some weird edge cases!) themselves.

@nex3
nex3 merged commit 0a291b0 into sass:main Oct 26, 2026
12 checks passed
@ntkme
ntkme deleted the fix-buffer-copy branch October 29, 2026 16:50
smorrisods added a commit to ongov/ontario-design-system that referenced this pull request Nov 5, 2026
sass-embedded's sync API intermittently fails with "Invalid protobuf"
on Node 24.22+ because sync-child-process <1.1.1 can hand back a
corrupted stdout buffer. This broke the React library's build-css step
in CI. sass-embedded allows ^1.0.2, so pin the fixed release via a
workspace override until sass-embedded requires it directly.

See sass/embedded-host-node#451 and sass/sync-child-process#38.

This branch was successfully deployed

1 active deployment
github-pages — 51df4f8e Deployed Oct 26, 2026 by nex3 via typedoc #93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants