Skip to content

fix: remove unsound Vec transmute in gaussian_blur#276

Open
tmchow wants to merge 2 commits into
Aloxaf:masterfrom
tmchow:fix/256-blur-unsoundness
Open

fix: remove unsound Vec transmute in gaussian_blur#276
tmchow wants to merge 2 commits into
Aloxaf:masterfrom
tmchow:fix/256-blur-unsoundness

Conversation

@tmchow

@tmchow tmchow commented Apr 5, 2026

Copy link
Copy Markdown

The gaussian_blur function casts *mut Vec<u8> to *mut Vec<[u8; 4]> and dereferences it. Vec has repr(Rust), so this is UB.

Replaced the transmute with std::slice::from_raw_parts_mut to reinterpret the raw byte buffer as &mut [[u8; 4]] instead. Same memory layout, no copies, no set_len calls.

Fixes #256

This contribution was developed with AI assistance (Claude Code).

Compound Engineering

tmchow added 2 commits April 4, 2026 22:49
Replace the `*mut Vec<u8> as *mut Vec<[u8; 4]>` cast with
`std::slice::from_raw_parts_mut` to reinterpret the raw byte
buffer as `&mut [[u8; 4]]`. Vec has `repr(Rust)` so the old
transmute was undefined behavior.

Fixes Aloxaf#256
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.

Unsoundness of gaussian_blur

1 participant