-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove isize overflow check for zst offsets (#3897)
#3755 introduced additional safety checks for the `offset` intrinsic, including a check for whether `count` overflows `isize`. However, such overflow is allowed for ZSTs. This PR changes the model to check for ZSTs before computing the offset to avoid triggering an overflow failure for ZSTs. I also moved an existing test called `offset-overflow` into another test, since #3755 changed the failure for that test to be about an out of bounds allocation, not an isize overflow. Resolves #3896 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
- Loading branch information
1 parent
51de000
commit 2e95d8b
Showing
7 changed files
with
74 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
tests/expected/offset-bounds-check/out_of_bounds_ub_check.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Failed Checks: Offset result and original pointer must point to the same allocation | ||
Verification failed for - check_ptr_oob | ||
Failed Checks: Offset result and original pointer must point to the same allocation | ||
|
||
Complete - 1 successfully verified harnesses, 1 failures, 2 total. | ||
Verification failed for - test_offset_overflow | ||
Verification failed for - check_ptr_oob | ||
Complete - 1 successfully verified harnesses, 2 failures, 3 total. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<usize as kani::rustc_intrinsics::ToISize>::to_isize.safety_check\ | ||
- Status: FAILURE\ | ||
- Description: "Offset value overflows isize" | ||
|
||
Failed Checks: Offset value overflows isize | ||
|
||
Verification failed for - test_non_zst | ||
Complete - 1 successfully verified harnesses, 1 failures, 2 total. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Checks that `offset` does not accept a `count` greater than isize::MAX, | ||
// except for ZSTs, c.f. https://github.com/model-checking/kani/issues/3896 | ||
|
||
#[kani::proof] | ||
fn test_zst() { | ||
let mut x = (); | ||
let ptr: *mut () = &mut x as *mut (); | ||
let count: usize = (isize::MAX as usize) + 1; | ||
let _ = unsafe { ptr.add(count) }; | ||
} | ||
|
||
#[kani::proof] | ||
fn test_non_zst() { | ||
let mut x = 7; | ||
let ptr: *mut i32 = &mut x as *mut i32; | ||
let count: usize = (isize::MAX as usize) + 1; | ||
let _ = unsafe { ptr.add(count) }; | ||
} |