@@ -4,7 +4,7 @@ use std::convert::TryFrom;
4
4
use rustc:: mir;
5
5
use rustc:: mir:: interpret:: { InterpResult , PointerArithmetic } ;
6
6
use rustc:: ty;
7
- use rustc:: ty:: layout:: { Align , LayoutOf , Size } ;
7
+ use rustc:: ty:: layout:: { Align , LayoutOf } ;
8
8
use rustc_apfloat:: Float ;
9
9
use rustc_span:: source_map:: Span ;
10
10
@@ -226,11 +226,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
226
226
=> {
227
227
let elem_ty = substs. type_at ( 0 ) ;
228
228
let elem_layout = this. layout_of ( elem_ty) ?;
229
- let elem_size = elem_layout. size . bytes ( ) ;
230
229
let count = this. read_scalar ( args[ 2 ] ) ?. to_machine_usize ( this) ?;
231
230
let elem_align = elem_layout. align . abi ;
232
231
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) ) ?;
234
234
let src = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
235
235
let src = this. memory . check_ptr_access ( src, size, elem_align) ?;
236
236
let dest = this. read_scalar ( args[ 1 ] ) ?. not_undef ( ) ?;
@@ -493,7 +493,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
493
493
let val_byte = this. read_scalar ( args[ 1 ] ) ?. to_u8 ( ) ?;
494
494
let ptr = this. read_scalar ( args[ 0 ] ) ?. not_undef ( ) ?;
495
495
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`" ) ) ?;
497
498
this. memory
498
499
. write_bytes ( ptr, iter:: repeat ( val_byte) . take ( byte_count. bytes ( ) as usize ) ) ?;
499
500
}
0 commit comments