@@ -531,7 +531,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
531
531
) -> InterpResult < ' tcx , Pointer < Option < M :: PointerTag > > > {
532
532
// We cannot overflow i64 as a type's size must be <= isize::MAX.
533
533
let pointee_size = i64:: try_from ( self . layout_of ( pointee_ty) ?. size . bytes ( ) ) . unwrap ( ) ;
534
- // The computed offset, in bytes, cannot overflow an isize.
534
+ // The computed offset, in bytes, must not overflow an isize.
535
+ // `checked_mul` enforces a too small bound, but no actual allocation can be big enough for
536
+ // the difference to be noticeable.
535
537
let offset_bytes =
536
538
offset_count. checked_mul ( pointee_size) . ok_or ( err_ub ! ( PointerArithOverflow ) ) ?;
537
539
// The offset being in bounds cannot rely on "wrapping around" the address space.
@@ -563,6 +565,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
563
565
let count = self . read_scalar ( & count) ?. to_machine_usize ( self ) ?;
564
566
let layout = self . layout_of ( src. layout . ty . builtin_deref ( true ) . unwrap ( ) . ty ) ?;
565
567
let ( size, align) = ( layout. size , layout. align . abi ) ;
568
+ // `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
569
+ // but no actual allocation can be big enough for the difference to be noticeable.
566
570
let size = size. checked_mul ( count, self ) . ok_or_else ( || {
567
571
err_ub_format ! (
568
572
"overflow computing total size of `{}`" ,
@@ -588,6 +592,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
588
592
let byte = self . read_scalar ( & byte) ?. to_u8 ( ) ?;
589
593
let count = self . read_scalar ( & count) ?. to_machine_usize ( self ) ?;
590
594
595
+ // `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
596
+ // but no actual allocation can be big enough for the difference to be noticeable.
591
597
let len = layout
592
598
. size
593
599
. checked_mul ( count, self )
0 commit comments