interpret: make isize::MAX the limit for dynamic value sizes
This commit is contained in:
parent
df20355fa9
commit
a421cbbead
3 changed files with 15 additions and 8 deletions
|
@ -23,8 +23,8 @@ use rustc_target::abi::{call::FnAbi, Align, HasDataLayout, Size, TargetDataLayou
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
AllocCheck, AllocId, GlobalId, Immediate, InterpErrorInfo, InterpResult, MPlaceTy, Machine,
|
AllocCheck, AllocId, GlobalId, Immediate, InterpErrorInfo, InterpResult, MPlaceTy, Machine,
|
||||||
MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer, Provenance,
|
MemPlace, MemPlaceMeta, Memory, MemoryKind, Operand, Place, PlaceTy, Pointer,
|
||||||
Scalar, ScalarMaybeUninit, StackPopJump,
|
PointerArithmetic, Provenance, Scalar, ScalarMaybeUninit, StackPopJump,
|
||||||
};
|
};
|
||||||
use crate::transform::validate::equal_up_to_regions;
|
use crate::transform::validate::equal_up_to_regions;
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let size = size.align_to(align);
|
let size = size.align_to(align);
|
||||||
|
|
||||||
// Check if this brought us over the size limit.
|
// Check if this brought us over the size limit.
|
||||||
if size.bytes() >= self.tcx.data_layout.obj_size_bound() {
|
if size > self.max_size_of_val() {
|
||||||
throw_ub!(InvalidMeta("total size is bigger than largest supported object"));
|
throw_ub!(InvalidMeta("total size is bigger than largest supported object"));
|
||||||
}
|
}
|
||||||
Ok(Some((size, align)))
|
Ok(Some((size, align)))
|
||||||
|
@ -694,9 +694,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let elem = layout.field(self, 0);
|
let elem = layout.field(self, 0);
|
||||||
|
|
||||||
// Make sure the slice is not too big.
|
// Make sure the slice is not too big.
|
||||||
let size = elem.size.checked_mul(len, self).ok_or_else(|| {
|
let size = elem.size * len;
|
||||||
err_ub!(InvalidMeta("slice is bigger than largest supported object"))
|
if size > self.max_size_of_val() {
|
||||||
})?;
|
throw_ub!(InvalidMeta("slice is bigger than largest supported object"));
|
||||||
|
}
|
||||||
Ok(Some((size, elem.align.abi)))
|
Ok(Some((size, elem.align.abi)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,16 +110,17 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
.read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_SIZE).unwrap())?
|
.read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_SIZE).unwrap())?
|
||||||
.check_init()?;
|
.check_init()?;
|
||||||
let size = size.to_machine_usize(self)?;
|
let size = size.to_machine_usize(self)?;
|
||||||
|
let size = Size::from_bytes(size);
|
||||||
let align = vtable
|
let align = vtable
|
||||||
.read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_ALIGN).unwrap())?
|
.read_ptr_sized(pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_ALIGN).unwrap())?
|
||||||
.check_init()?;
|
.check_init()?;
|
||||||
let align = align.to_machine_usize(self)?;
|
let align = align.to_machine_usize(self)?;
|
||||||
let align = Align::from_bytes(align).map_err(|e| err_ub!(InvalidVtableAlignment(e)))?;
|
let align = Align::from_bytes(align).map_err(|e| err_ub!(InvalidVtableAlignment(e)))?;
|
||||||
|
|
||||||
if size >= self.tcx.data_layout.obj_size_bound() {
|
if size > self.max_size_of_val() {
|
||||||
throw_ub!(InvalidVtableSize);
|
throw_ub!(InvalidVtableSize);
|
||||||
}
|
}
|
||||||
Ok((Size::from_bytes(size), align))
|
Ok((size, align))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_new_vtable_after_trait_upcasting_from_vtable(
|
pub fn read_new_vtable_after_trait_upcasting_from_vtable(
|
||||||
|
|
|
@ -18,6 +18,11 @@ pub trait PointerArithmetic: HasDataLayout {
|
||||||
self.data_layout().pointer_size
|
self.data_layout().pointer_size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn max_size_of_val(&self) -> Size {
|
||||||
|
Size::from_bytes(self.machine_isize_max())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn machine_usize_max(&self) -> u64 {
|
fn machine_usize_max(&self) -> u64 {
|
||||||
self.pointer_size().unsigned_int_max().try_into().unwrap()
|
self.pointer_size().unsigned_int_max().try_into().unwrap()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue