imazen / imageflow

High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
https://docs.imageflow.io/
GNU Affero General Public License v3.0
4.14k stars 140 forks source link

transpose: Fix invalid_reference_casting errors #649

Closed andersk closed 2 months ago

andersk commented 2 months ago

Fixes this build error with current Rust nightly:

error: casting references to a bigger memory layout than the backing allocation is undefined behavior, even if the reference is unused
   --> imageflow_core/src/graphics/transpose.rs:122:13
    |
122 |                *(&mut *(*to).pixels.offset(
    |   _____________^______-
    |  |_____________|
    | ||
123 | ||                 x.wrapping_mul(4u32)
124 | ||                     .wrapping_add(y.wrapping_mul((*to).stride)) as isize,
125 | ||             ) as *mut libc::c_uchar as *mut u32) = *(&mut *(*from).pixels.offset(
    | ||_____________- backing allocation comes from here
...   |
128 | |              ) as *mut libc::c_uchar
129 | |                  as *mut u32);
    | |_____________________________^
    |
    = note: casting from `u8` (1 bytes) to `u32` (4 bytes)
    = note: `#[deny(invalid_reference_casting)]` on by default