Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread 'main' panicked at 'Size::from_bytes: 18446744073709551614 bytes in bits doesn't fit in u64 #50917

Closed
bjorn3 opened this issue May 20, 2018 · 0 comments · Fixed by #50916

Comments

@bjorn3
Copy link
Member

bjorn3 commented May 20, 2018

This is miri test run-pass/ptr_arith_offset_overflow.rs

fn main() {
    let v = [1i16, 2];
    let x = &v[1] as *const i16;
    // Adding 2*isize::max and then 1 is like substracting 1
    let x = x.wrapping_offset(isize::max_value());
    let x = x.wrapping_offset(isize::max_value());
    let x = x.wrapping_offset(1);
    assert_eq!(unsafe { *x }, 1);
}
backtrace
thread 'main' panicked at 'Size::from_bytes: 18446744073709551614 bytes in bits doesn't fit in u64', librustc_target/abi/mod.rs:237:13
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:467
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:350
   7: rustc_target::abi::Size::from_bytes
   8: rustc::mir::interpret::MemoryPointer::wrapping_signed_offset
             at /checkout/src/librustc/mir/interpret/mod.rs:123
   9: rustc::mir::interpret::value::Pointer::wrapping_signed_offset
             at /checkout/src/librustc/mir/interpret/value.rs:155
  10: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, miri::Evaluator<'tcx>> as miri::helpers::EvalContextExt<'tcx>>::wrapping_pointer_offset
             at src/helpers.rs:54
  11: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, miri::Evaluator<'tcx>> as miri::intrinsic::EvalContextExt<'tcx>>::call_intrinsic
             at src/intrinsic.rs:75
  12: <miri::Evaluator<'tcx> as rustc_mir::interpret::machine::Machine<'mir, 'tcx>>::call_intrinsic
             at src/lib.rs:254
  13: rustc_mir::interpret::terminator::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_fn_call
             at /checkout/src/librustc_mir/interpret/terminator/mod.rs:268
  14: rustc_mir::interpret::terminator::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_terminator
             at /checkout/src/librustc_mir/interpret/terminator/mod.rs:106
  15: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::terminator
             at /checkout/src/librustc_mir/interpret/step.rs:109
  16: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::step
             at /checkout/src/librustc_mir/interpret/step.rs:43
  17: miri::eval_main::run_main
             at src/lib.rs:157
  18: miri::eval_main
             at src/lib.rs:170
  19: miri::after_analysis
             at src/bin/miri.rs:147
  20: <miri::MiriCompilerCalls as rustc_driver::CompilerCalls<'a>>::build_controller::{{closure}}
             at src/bin/miri.rs:88
  21: rustc_driver::driver::compile_input::{{closure}}
  22: rustc::ty::context::tls::enter_context
  23: <std::thread::local::LocalKey<T>>::with
  24: rustc::ty::context::TyCtxt::create_and_enter
  25: rustc_driver::driver::compile_input
  26: rustc_driver::run_compiler_with_pool
  27: syntax::with_globals
  28: rustc_driver::run_compiler
  29: miri::main
             at src/bin/miri.rs:237
  30: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  31: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  32: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  33: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:374
             at libstd/rt.rs:58
  34: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  35: main
  36: __libc_start_main
  37: _start
query stack during panic:
end of query stack

screenshot_2018-05-20 miri tests run-pass ptr_arith_offset_overflow rs

bors added a commit that referenced this issue May 23, 2018
Allow `Size` to be any valid `u64`

cc rust-lang/miri#378 (comment)

The alternative is to make mir::interpret's pointer offsets not be `Size`

fixes #50917

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant