Skip to content

reject growable SharedArrayBuffer without hooks#1523

Open
jdcaperon wants to merge 1 commit into
quickjs-ng:masterfrom
jdcaperon:jack-sab-grow-hooks
Open

reject growable SharedArrayBuffer without hooks#1523
jdcaperon wants to merge 1 commit into
quickjs-ng:masterfrom
jdcaperon:jack-sab-grow-hooks

Conversation

@jdcaperon
Copy link
Copy Markdown

@jdcaperon jdcaperon commented Jun 1, 2026

This PR is AI assisted and human reviewed to the limits of the human, feel free to close and I can re-raise as an issue.

In quickjs.c, js_array_buffer_constructor3() allowed growable SharedArrayBuffer construction without SAB allocator hooks.

Context

Growable SharedArrayBuffer construction could succeed on runtimes created with JS_NewRuntime() when the embedder had not installed SharedArrayBuffer allocator hooks.

In that configuration, construction allocated only the initial byteLength, while SharedArrayBuffer.prototype.grow() later assumed the backing store covered maxByteLength and only updated the logical byte length.

That mismatch could let typed array and DataView access reach beyond the native allocation after growth.

Intent

Fail closed during JS-created growable SharedArrayBuffer construction when sab_alloc is unavailable.

Fixed-length SharedArrayBuffer construction remains allowed without hooks. Runtimes that install SAB allocator hooks can still construct and grow SABs backed by the upfront maxByteLength allocation.

The C API regression coverage checks the default-runtime rejection path, preserves fixed-length SAB behavior, and verifies hooked-runtime growth exposes zero-filled bytes beyond the initial length.

@jdcaperon jdcaperon changed the title [SAB] Reject growable SharedArrayBuffer without hooks reject growable SharedArrayBuffer without hooks Jun 1, 2026
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