Description
Unsoundness
Hi, we considered that flip_bitmap_x
and flip_bitmap_y
break the alignment requirements of unsafe function slice::from_raw_parts_mut
with unaligned raw pointer.
webrender/wr_glyph_rasterizer/src/platform/unix/font.rs
Lines 353 to 357 in b6b2f65
webrender/wr_glyph_rasterizer/src/platform/unix/font.rs
Lines 361 to 368 in b6b2f65
Since both of the functions are private, we also checked whether the callers of functions passed the type aligned to 4 bytes actually in the library. We found that in the function rasterize_glyph
webrender/wr_glyph_rasterizer/src/platform/unix/font.rs
Lines 1062 to 1068 in b6b2f65
final_buffer
is created from u8
slice in line 948, which is aligned to 1 byte. Therefore, we are sure that final_buffer
is cast to 4 bytes and creates an unaligned pointer.
When the slice is created from unaligned raw pointer, the undefined behavior could lead to inconsistent results in different systems and architectures, which will change the pixels
values here. Considering use ptr::copy_non_overlapping
to create a new type aligned to 4 bytes before passing into from_raw_parts
would be more safe.