Skip to content

Fix buffer initialization overread in Metal - #118

Open
tryk016 wants to merge 1 commit into
Try:masterfrom
tryk016:codex/pr-tempest-metal-buffer-init
Open

tryk016 wants to merge 1 commit into
Try:masterfrom
tryk016:codex/pr-tempest-metal-buffer-init

Conversation

@tryk016

@tryk016 tryk016 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Buffer allocations are rounded up to 64 bytes, but newBuffer(data, roundSize, ...) also copies that many bytes from the source. ASan catches a 64-byte read from the 24-byte data in MetalApi.VboInit.

Keep the padded allocation and initialize it through update(data, 0, size). The same test passes with ASan after this change.

const size_t roundSize = ((size+64-1)/64)*64; // for uniforms/ssbo structures in msl

const MTL::ResourceOptions flg = f | MTL::HazardTrackingModeDefault;
if(data==nullptr) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

maybe keep it with extra check of roundSize == size ?
Basically intent here is leverage fast-driver initialization, if possible

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