Skip to content

fix: Protect against GC from validate_bytes#1447

Merged
zkat merged 8 commits into
mainfrom
sy/validate-bytes
May 5, 2026
Merged

fix: Protect against GC from validate_bytes#1447
zkat merged 8 commits into
mainfrom
sy/validate-bytes

Conversation

@TartanLlama

Copy link
Copy Markdown
Contributor

In the case that it is given an ArrayBufferView, validate_bytes returns a pointer to a buffer that may be GC'ed. The current uses of validate_bytes are careful to not add any potentially GC-triggering calls between the call to validate_bytes and hostcalls, but this may change in the future, and there is nothing in place to ensure the GC does not occur. As such, this PR changes validate_bytes to additionally return an optional GC guard, that calling code can hold on to to ensure there is no GC at runtime while the pointer is live.

Honestly I'm not sure this is all worth it and I'm tempted to just return a std::vector from that function, but I figured I'd avoid regressing performance in this case while adding some additional safety.

There is no test for this PR, because it is adding defensive code for potential future uses of validate_bytes, or changes to existing callers.

@zkat zkat enabled auto-merge (squash) May 1, 2026 22:47
@zkat

zkat commented May 4, 2026

Copy link
Copy Markdown
Member

This has some build errors

@zkat zkat merged commit be0867b into main May 5, 2026
25 of 29 checks passed
@zkat zkat deleted the sy/validate-bytes branch May 5, 2026 09:24
zkat added a commit that referenced this pull request May 7, 2026
pull Bot pushed a commit to eduardomourar/js-compute-runtime that referenced this pull request May 14, 2026
Co-authored-by: Kat Marchán <kzm@zkat.tech>
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.

3 participants