Skip to content

AnySlice may yield unexpected results #1009

Closed

Description

@celinval

I tried this code:

#[kani::proof]
fn check_out_of_bounds() {
    let mut bytes = kani::slice::any_slice::<u8, 5>();
    let val = unsafe { *bytes.get_slice().as_ptr().add(4) };
    kani::assume(val != 0);
    assert_ne!(val, 0);
}

using the following command line invocation:

kani check.rs

I expected to see this happen: I expected that accessing position 4 of any_slice may fail with out of bounds access.

Instead, this happened: The verification succeeded. Because any_slice always allocates a buffer with size MAX_SIZE (in this case 5), the access to position 4 is always valid.

Activity

  1. added
    [C] Bug
    [F] Soundness
    on Apr 4, 2022
  2. adpaco commented on Apr 4, 2022

    @adpaco
    Contributor

    Isn't this another case of uninitialized memory?
    Just to be clear, why do you assume val != 0?

  3. self-assigned this
    on Apr 4, 2022
  4. celinval commented on Apr 7, 2022

    @celinval
    ContributorAuthor

    Isn't this another case of uninitialized memory? Just to be clear, why do you assume val != 0?

    I was just using the variable. Nothing relevant to the issue itself.

  5. added a commit that references this issue on Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug[F] Soundness

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions