Skip to content

Miri catches some undefined behavior #2381

Closed
@dralley

Description

@dralley
[dalley@localhost RustPython]$ cargo +nightly miri run
   Compiling rustpython v0.1.2 (/home/dalley/Devel/rustpython-dev/RustPython)
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `/home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri target/x86_64-unknown-linux-gnu/debug/rustpython`
error: Undefined Behavior: incorrect layout on deallocation: alloc1637055 has size 120 and alignment 8, but gave size 72 and alignment 8
   --> /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:104:14
    |
104 |     unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: alloc1637055 has size 120 and alignment 8, but gave size 72 and alignment 8
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
            
    = note: inside `std::alloc::dealloc` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:104:14
    = note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:239:22
    = note: inside `<std::sync::Weak<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>> as std::ops::Drop>::drop` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:1928:22
    = note: inside `std::intrinsics::drop_in_place::<std::sync::Weak<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>> - shim(Some(std::sync::Weak<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>))` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:179:1
    = note: inside `std::mem::drop::<std::sync::Weak<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:882:24
    = note: inside `std::sync::Arc::<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>::drop_slow` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:954:9
    = note: inside `<std::sync::Arc<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>> as std::ops::Drop>::drop` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:1471:13
    = note: inside `std::intrinsics::drop_in_place::<std::sync::Arc<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>> - shim(Some(std::sync::Arc<rustpython::rustpython_vm::pyobject::PyObject<rustpython::rustpython_vm::pyobjectrc::Erased>>))` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:179:1
    = note: inside `std::intrinsics::drop_in_place::<rustpython::rustpython_vm::pyobject::PyObjectRef> - shim(Some(rustpython::rustpython_vm::pyobject::PyObjectRef))` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:179:1
    = note: inside `std::intrinsics::drop_in_place::<std::option::Option<rustpython::rustpython_vm::pyobject::PyObjectRef>> - shim(Some(std::option::Option<rustpython::rustpython_vm::pyobject::PyObjectRef>))` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:179:1
    = note: inside `rustpython::rustpython_vm::builtins::PyType::set_str_attr::<rustpython::rustpython_vm::pyobject::PyObjectRef>` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/builtins/pytype.rs:104:56
    = note: inside `rustpython::rustpython_vm::builtins::property::init` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/macros.rs:69:13
    = note: inside `rustpython::rustpython_vm::types::TypeZoo::extend` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/types.rs:223:9
    = note: inside `rustpython::rustpython_vm::pyobject::PyContext::init` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/pyobject.rs:157:9
    = note: inside `<fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init} as std::ops::FnOnce<()>>::call_once - shim(fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init})` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    = note: inside closure at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/lib.rs:834:57
    = note: inside closure at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/imp_std.rs:93:19
    = note: inside `once_cell::imp::initialize_inner` at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/imp_std.rs:167:31
    = note: inside `once_cell::imp::OnceCell::<rustpython::rustpython_vm::pyobject::PyContext>::initialize::<[closure@rustpython::rustpython_vm::rustpython_common::lock::OnceCell<rustpython::rustpython_vm::pyobject::PyContext>::get_or_init<fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init}>::{closure#0}], rustpython::rustpython_vm::rustpython_common::lock::OnceCell<T>::get_or_init::Void>` at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/imp_std.rs:91:9
    = note: inside `rustpython::rustpython_vm::rustpython_common::lock::OnceCell::<rustpython::rustpython_vm::pyobject::PyContext>::get_or_try_init::<[closure@rustpython::rustpython_vm::rustpython_common::lock::OnceCell<rustpython::rustpython_vm::pyobject::PyContext>::get_or_init<fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init}>::{closure#0}], rustpython::rustpython_vm::rustpython_common::lock::OnceCell<T>::get_or_init::Void>` at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/lib.rs:874:13
    = note: inside `rustpython::rustpython_vm::rustpython_common::lock::OnceCell::<rustpython::rustpython_vm::pyobject::PyContext>::get_or_init::<fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init}>` at /home/dalley/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.5.2/src/lib.rs:834:19
    = note: inside `rustpython::rustpython_vm::rustpython_common::static_cell::StaticCell::<rustpython::rustpython_vm::pyobject::PyContext>::get_or_init::<fn() -> rustpython::rustpython_vm::pyobject::PyContext {rustpython::rustpython_vm::pyobject::PyContext::init}>` at /home/dalley/Devel/rustpython-dev/RustPython/common/src/static_cell.rs:95:13
    = note: inside `rustpython::rustpython_vm::pyobject::PyContext::new` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/pyobject.rs:165:9
    = note: inside `rustpython::rustpython_vm::VirtualMachine::new` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/vm.rs:232:19
    = note: inside `rustpython::rustpython_vm::Interpreter::new_with_init::<[closure@rustpython::run<[closure@src/main.rs:2:21: 2:29]>::{closure#0}]>` at /home/dalley/Devel/rustpython-dev/RustPython/vm/src/vm.rs:1775:22
    = note: inside `rustpython::run::<[closure@src/main.rs:2:21: 2:29]>` at /home/dalley/Devel/rustpython-dev/RustPython/src/lib.rs:101:18
note: inside `main` at src/main.rs:2:5
   --> src/main.rs:2:5
    |
2   |     rustpython::run(|_vm| {})
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    = note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:125:18
    = note: inside closure at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:66:18
    = note: inside `std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:259:13
    = note: inside `std::panicking::r#try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:379:40
    = note: inside `std::panicking::r#try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:343:19
    = note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:396:14
    = note: inside `std::rt::lang_start_internal` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:51:25
    = note: inside `std::rt::lang_start::<()>` at /home/dalley/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:65:5

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions