Skip to content

Commit

Permalink
Fix panic caused by improperly aligned read (#675)
Browse files Browse the repository at this point in the history
Under certain circumstances, Vello could attempt an improperly aligned
read, which would cause bytemuck to panic.

This uses `bytemuck::pod_read_unaligned` instead of
`bytemuck::from_bytes` to achieve the same thing without the possibility
of a panic.
  • Loading branch information
timtom-dev authored Aug 29, 2024
1 parent aaa9f5f commit ede0e47
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vello_encoding/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,10 @@ impl<'a> PathEncoder<'a> {
if len < 8 {
return None;
}
let pts: &[f32; 2] = bytemuck::from_bytes(&self.data[len - 8..len]);
Some((pts[0], pts[1]))
Some((
bytemuck::pod_read_unaligned::<f32>(&self.data[len - 8..len - 4]),
bytemuck::pod_read_unaligned::<f32>(&self.data[len - 4..len]),
))
}

fn is_zero_length_segment(
Expand Down

0 comments on commit ede0e47

Please sign in to comment.