@@ -4,7 +4,7 @@ use std::convert::TryFrom;
44use rustc:: mir;
55use rustc:: mir:: interpret:: { InterpResult , PointerArithmetic } ;
66use rustc:: ty;
7- use rustc:: ty:: layout:: { Align , LayoutOf , Size } ;
7+ use rustc:: ty:: layout:: { Align , LayoutOf } ;
88use rustc_apfloat:: Float ;
99use rustc_span:: source_map:: Span ;
1010
@@ -226,11 +226,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226226 => {
227227 let elem_ty = substs. type_at ( 0 ) ;
228228 let elem_layout = this. layout_of ( elem_ty) ?;
229- let elem_size = elem_layout. size . bytes ( ) ;
230229 let count = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
231230 let elem_align = elem_layout. align . abi ;
232231
233- let size = Size :: from_bytes ( count) * elem_size;
232+ let size = elem_layout. size . checked_mul ( count, this)
233+ . ok_or_else ( || err_ub_format ! ( "overflow computing total size of `{}`" , intrinsic_name) ) ?;
234234 let src = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
235235 let src = this. memory . check_ptr_access ( src, size, elem_align) ?;
236236 let dest = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
@@ -493,7 +493,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
493493 let val_byte = this. read_scalar ( args[ 1 ] ) ?. to_u8 ( ) ?;
494494 let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
495495 let count = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
496- let byte_count = ty_layout. size * count;
496+ let byte_count = ty_layout. size . checked_mul ( count, this)
497+ . ok_or_else ( || err_ub_format ! ( "overflow computing total size of `write_bytes`" ) ) ?;
497498 this. memory
498499 . write_bytes ( ptr, iter:: repeat ( val_byte) . take ( byte_count. bytes ( ) as usize ) ) ?;
499500 }
0 commit comments