Skip to content

Fix transmute_slice UB: add alignment, divisibility, and ZST guards#917

Open
kimjune01 wants to merge 1 commit into
FyroxEngine:masterfrom
kimjune01:fix/transmute-slice-alignment-ub
Open

Fix transmute_slice UB: add alignment, divisibility, and ZST guards#917
kimjune01 wants to merge 1 commit into
FyroxEngine:masterfrom
kimjune01:fix/transmute-slice-alignment-ub

Conversation

@kimjune01
Copy link
Copy Markdown

Summary

  • Adds runtime alignment assertion before slice::from_raw_parts to prevent misaligned pointer UB (reported in [Undefined Behavior] Misaligned Raw Pointer with transmute_slice #877)
  • Adds byte-length divisibility assertion to catch truncated trailing bytes
  • Adds ZST guard to prevent division by zero
  • Adds Pod trait bounds to fyrox-core::transmute_slice to ensure valid bit patterns for any byte sequence
  • Applies same alignment + divisibility guards to fyrox-texture's private transmute_slice and transmute_slice_mut

Test plan

  • cargo check -p fyrox-core -p fyrox-texture -p fyrox-graphics passes
  • Existing tests in fyrox-graphics/src/uniform.rs that call transmute_slice still pass
  • CI should verify no regressions across the full test suite

Closes #877

Adds runtime checks before calling slice::from_raw_parts in
transmute_slice, transmute_slice_mut (both fyrox-core and fyrox-texture):
- Alignment assertion prevents misaligned pointer UB
- Divisibility assertion catches truncated trailing bytes
- ZST assertion prevents division by zero
- Pod trait bounds on fyrox-core's public API ensure valid bit patterns

Closes FyroxEngine#877
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.

[Undefined Behavior] Misaligned Raw Pointer with transmute_slice

1 participant