Skip to content

[TB] Strong protectors prevent deallocation even when they are zero-sized #4579

@JoJoDeveloping

Description

@JoJoDeveloping

Consider the following program:

fn protectme(_x: &mut (), y: *mut u8) {
    let y = unsafe { Box::from_raw(y) };
    drop(y)
}

fn main() {
    let y = Box::new(42u8);
    let y = Box::leak(y);
    let x = unsafe { &mut *(y as *mut u8 as *mut ()) };
    protectme(x, y);
}

The deallocation of the Box in protectme is currently reported as UB by Tree Borrows (but not by SB) because of the protector on _x. However, this protector is zero-sized (no offset have yet been accessed) so it's not actually protecting anything. It should not prevent the deallocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions