Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check WasmPtr alignment before reading from it #5444

Open
xdoardo opened this issue Feb 28, 2025 — with Linear · 0 comments · May be fixed by #5449
Open

Check WasmPtr alignment before reading from it #5444

xdoardo opened this issue Feb 28, 2025 — with Linear · 0 comments · May be fixed by #5449
Assignees
Labels
bug Something isn't working

Comments

Copy link
Collaborator

xdoardo commented Feb 28, 2025

Currently, the code that reads from a given pointer in memory does not perform any check on the alignment of the pointer:

/// Reads the location pointed to by this `WasmRef`.
#[inline]
pub fn read(self) -> Result<T, MemoryAccessError> {
  let mut out = MaybeUninit::uninit();
  let buf =
      unsafe { slice::from_raw_parts_mut(out.as_mut_ptr() as *mut u8, mem::size_of::<T>()) };
  self.buffer.read(self.offset, buf)?;
  Ok(unsafe { out.assume_init() })
}

This can cause panics. This part of the code should check if the pointer is aligned before creating the slice, and return an error in case it is not aligned.

@xdoardo xdoardo added the bug Something isn't working label Feb 28, 2025 — with Linear
@xdoardo xdoardo self-assigned this Feb 28, 2025
@xdoardo xdoardo linked a pull request Mar 3, 2025 that will close this issue
@xdoardo xdoardo linked a pull request Mar 3, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant