Skip to content

vld3* alignment requirement #2128

@awxkee

Description

@awxkee

Current NEON vld3* loading implementation inserts an alignment requirement where none is required.

Consider following code:

use std::arch::aarch64::*;
use std::mem::MaybeUninit;

fn main() {
    let data: Vec<u8> = vec![0u8; 200];

    let base = data.as_ptr() as usize;
    let misaligned_offset = if base % 16 == 0 { 2 } else { 0 };

    let ptr = unsafe {
        data.as_ptr().add(misaligned_offset) as *const f32
    };
    unsafe {
        type W = [f32; 16]; 
        let mut mem = MaybeUninit::<W>::uninit();
        std::ptr::copy_nonoverlapping(
            ptr,                    
            mem.as_mut_ptr().cast::<f32>(),
            12,           
        );
        let _ = mem.assume_init();
    }

    println!("we're done");
}

Since copy_nonoverlapping requires both pointers to be aligned to at least align_of::<f32>(), passing a pointer that is not sufficiently aligned is an UB. I have not checked the release build, but this is immediately detected by the fuzzer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions