Skip to content

fix!: require writable external buffer storage - #58

Merged
nazarhussain merged 2 commits into
mainfrom
fix/external-buffer-writable-memory
Jul 27, 2026
Merged

fix!: require writable external buffer storage#58
nazarhussain merged 2 commits 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
Comment thread src/Env.zig
Comment thread src/Env.zig Outdated
@GrapeBaBa GrapeBaBa changed the title fix: require writable external buffer storage fix!: require writable external buffer storage Jul 24, 2026
@GrapeBaBa
GrapeBaBa requested a review from nazarhussain July 25, 2026 15:05
@nazarhussain
nazarhussain merged commit 8fd898f into main Jul 27, 2026
5 checks passed
nazarhussain pushed a commit that referenced this pull request Aug 18, 2026
🤖 I have created a release *beep* *boop*
---


##
[4.0.0](zapi-v3.1.0...zapi-v4.0.0)
(2026-08-18)


### ⚠ BREAKING CHANGES

* isolate DSL class tags across addons
([#67](#67))
* manage external buffer lifetime
([#66](#66))
* require writable external buffer storage
([#58](#58))

### Features

* add owned typed arrays
([#68](#68))
([b92c2de](b92c2de))
* **js:** add exact u32 conversion
([#71](#71))
([d6b21e1](d6b21e1))
* **js:** add typed array toArray
([#70](#70))
([ab42ab0](ab42ab0))
* **js:** export module/namespace consts and enums
([#73](#73))
([76dc0db](76dc0db))


### Bug Fixes

* **dsl:** support class pointer arguments
([#50](#50))
([9dd2111](9dd2111))
* harden N-API boundary against JS-triggerable memory bugs
([#60](#60))
([fff76f3](fff76f3))
* isolate DSL class tags across addons
([#67](#67))
([3ab8c11](3ab8c11))
* manage external buffer lifetime
([#66](#66))
([d134a6a](d134a6a))
* **napi:** receive raw pointer out parameters
([#57](#57))
([fde4a9a](fde4a9a))
* remove redundant platform check from musl detection
([#64](#64))
([0d4829c](0d4829c))
* require writable external buffer storage
([#58](#58))
([8fd898f](8fd898f))
* restore registerDecls on Zig 0.16
([#59](#59))
([7f3af3e](7f3af3e))


### Code Refactoring

* **js:** unify env lifecycle refcounting
([#53](#53))
([d3d5056](d3d5056))


### Miscellaneous Chores

* define changelog sections for release-please
([#54](#54))
([1c5e7b4](1c5e7b4))
* update dev deps ([#74](#74))
([5121590](5121590))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants