Skip to content

fix: require writable external buffer storage#58

Open
GrapeBaBa wants to merge 1 commit into
mainfrom
fix/external-buffer-writable-memory
Open

fix: require writable external buffer storage#58
GrapeBaBa wants to merge 1 commit into
mainfrom
fix/external-buffer-writable-memory

Conversation

@GrapeBaBa

Copy link
Copy Markdown
Contributor

Motivation

External ArrayBuffer and Buffer constructors accepted []const u8 and removed constness before exposing the backing memory to JavaScript. JavaScript can mutate that memory, so immutable storage such as string literals could be written through, causing undefined behavior.

Callers with immutable input also need an owning copy API instead of being pushed toward the zero-copy external constructors.

Description

  • Require []u8 for external ArrayBuffer and Buffer backing storage and remove the internal @constCast operations.
  • Reject immutable byte slices used with the .external_buffer return hint.
  • Add createArrayBufferCopy for immutable input and document the existing Buffer copy behavior.
  • Add integration coverage for independently writable copies, empty ArrayBuffers, and mutable external Buffer sharing.

Validated with pnpm build, pnpm test:zig, and the hello-world Vitest suite. The full JS suite retains the pre-existing macOS musl-target failure in examples/targets/mod.test.ts.

@GrapeBaBa
GrapeBaBa marked this pull request as ready for review July 21, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant