-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
The knowledge about all the elements in an array can be used to run a single check instead of running the checks on each element one at a time (suggested in #53671 (comment)).
This is currently only done for strings, but could just as well be done for arrays of various types with Scalar
layout.
The E-easy part of this issue is to check for arrays/slices of the builtin integer types and simply verify that there are no relocations in the entire array and that the entire array has no undefined bytes. Should be possible by simply calling
rust/src/librustc_mir/interpret/memory.rs
Line 740 in 1114ab6
pub fn read_bytes(&self, ptr: Scalar, size: Size) -> EvalResult<'tcx, &[u8]> { |
Ok
. No need to actually check the value.
The E-medium part is to refactor
fn validate_scalar( |
rust/src/librustc_mir/interpret/validity.rs
Line 101 in 1114ab6
value: ScalarMaybeUndef, |
rust/src/librustc_mir/interpret/validity.rs
Lines 110 to 113 in 1114ab6
let value = match value { | |
ScalarMaybeUndef::Scalar(scalar) => scalar, | |
ScalarMaybeUndef::Undef => return validation_failure!("undefined bytes", path), | |
}; |
rust/src/librustc_mir/interpret/validity.rs
Line 166 in 1114ab6
let in_range = |bound: RangeInclusive<u128>| bound.contains(&bits); |