Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Undefined uninitialized behaviour panic on nightly since 1.49.0 #42

Closed
norru opened this issue Oct 21, 2020 · 3 comments
Closed

Undefined uninitialized behaviour panic on nightly since 1.49.0 #42

norru opened this issue Oct 21, 2020 · 3 comments
Assignees
Labels

Comments

@norru
Copy link
Contributor

norru commented Oct 21, 2020

I got 100% panic since upgrading nightly to 1.49.0. This causes 100% crash when writing images.

Update: reproduced in rust 1.51.0-nightly

This needs looking into as it kind of makes the library completely unusable on newer versions of rustc

rustc 1.49.0-nightly (31530e5d1 2020-10-20)

rust-lang/rust#73573

nico@devuan-3xS:~/Projects/3rdParty/openexr-rs$ RUST_BACKTRACE=1 cargo test
warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/frame_buffer.rs:215:36
    |
215 |         let mut channel = unsafe { mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/header.rs:356:33
    |
356 |         let mut name = unsafe { std::mem::uninitialized() };
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/header.rs:357:36
    |
357 |         let mut channel = unsafe { std::mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^

warning: the type `CEXR_Channel` does not permit being left uninitialized
   --> src/frame_buffer.rs:215:36
    |
215 |         let mut channel = unsafe { mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^
    |                                    |
    |                                    this code causes undefined behavior when executed
    |                                    help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
    |
    = note: `#[warn(invalid_value)]` on by default
note: enums have to be initialized to a variant
   --> /home/nico/Projects/3rdParty/openexr-rs/openexr-sys/src/bindings.rs:105:1
    |
105 | pub enum CEXR_PixelType { UINT = 0, HALF = 1, FLOAT = 2, }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the type `CEXR_Channel` does not permit being left uninitialized
   --> src/header.rs:357:36
    |
357 |         let mut channel = unsafe { std::mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                    |
    |                                    this code causes undefined behavior when executed
    |                                    help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
    |
note: enums have to be initialized to a variant
   --> /home/nico/Projects/3rdParty/openexr-rs/openexr-sys/src/bindings.rs:105:1
    |
105 | pub enum CEXR_PixelType { UINT = 0, HALF = 1, FLOAT = 2, }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: 5 warnings emitted

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/frame_buffer.rs:215:36
    |
215 |         let mut channel = unsafe { mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/header.rs:356:33
    |
356 |         let mut name = unsafe { std::mem::uninitialized() };
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
   --> src/header.rs:357:36
    |
357 |         let mut channel = unsafe { std::mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^

warning: the type `CEXR_Channel` does not permit being left uninitialized
   --> src/frame_buffer.rs:215:36
    |
215 |         let mut channel = unsafe { mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^
    |                                    |
    |                                    this code causes undefined behavior when executed
    |                                    help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
    |
    = note: `#[warn(invalid_value)]` on by default
note: enums have to be initialized to a variant
   --> /home/nico/Projects/3rdParty/openexr-rs/openexr-sys/src/bindings.rs:105:1
    |
105 | pub enum CEXR_PixelType { UINT = 0, HALF = 1, FLOAT = 2, }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the type `CEXR_Channel` does not permit being left uninitialized
   --> src/header.rs:357:36
    |
357 |         let mut channel = unsafe { std::mem::uninitialized() };
    |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
    |                                    |
    |                                    this code causes undefined behavior when executed
    |                                    help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
    |
note: enums have to be initialized to a variant
   --> /home/nico/Projects/3rdParty/openexr-rs/openexr-sys/src/bindings.rs:105:1
    |
105 | pub enum CEXR_PixelType { UINT = 0, HALF = 1, FLOAT = 2, }
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: 5 warnings emitted

    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/openexr-820bdf9eb2e33d8f

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/incremental_io-df68b4539a48d82c

running 1 test
test incremental_io ... FAILED

failures:

---- incremental_io stdout ----
thread 'incremental_io' panicked at 'attempted to leave type `openexr_sys::CEXR_Channel` uninitialized, which is invalid', /home/nico/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:659:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/158f8d034b15e65ba8dc0d066358dd0632bfcd6e/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/158f8d034b15e65ba8dc0d066358dd0632bfcd6e/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/158f8d034b15e65ba8dc0d066358dd0632bfcd6e/library/core/src/panicking.rs:50:5
   3: core::mem::uninitialized
             at /home/nico/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:659:9
   4: <openexr::header::ChannelIter as core::iter::traits::iterator::Iterator>::next
             at ./src/header.rs:357:36
   5: openexr::header::Header::validate_framebuffer_for_output
             at ./src/header.rs:262:21
   6: openexr::output::scanline_output_file::ScanlineOutputFile::write_pixels_incremental
             at ./src/output/scanline_output_file.rs:244:9
   7: incremental_io::incremental_io
             at ./tests/incremental_io.rs:27:9
   8: incremental_io::incremental_io::{{closure}}
             at ./tests/incremental_io.rs:8:1
   9: core::ops::function::FnOnce::call_once
             at /home/nico/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
  10: core::ops::function::FnOnce::call_once
             at /rustc/158f8d034b15e65ba8dc0d066358dd0632bfcd6e/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.


failures:
    incremental_io

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

error: test failed, to rerun pass '--test incremental_io'

stable rustc 1.47.0 does not trigger the panic.

@norru norru changed the title Undefined behaviour panic after rustc update causes 100% crash when writing image Undefined uninitialized behaviour panic on nightly 1.49.0 Oct 21, 2020
@cessen
Copy link
Owner

cessen commented Oct 21, 2020

Ah! Thank you for finding and reporting this. I'll take a look the next chance I get (though I'm a bit busy at the moment).

If you need a fix urgently, feel free to make a fix yourself and submit a PR, and I'll do my best to review, merge, and make a release with that more quickly.

@cessen cessen self-assigned this Oct 21, 2020
@cessen cessen added the bug label Oct 21, 2020
@norru
Copy link
Contributor Author

norru commented Oct 22, 2020 via email

@norru norru changed the title Undefined uninitialized behaviour panic on nightly 1.49.0 Undefined uninitialized behaviour panic on nightly since 1.49.0 Dec 30, 2020
norru added a commit to itadinanta/openexr-rs that referenced this issue Dec 30, 2020
@norru
Copy link
Contributor Author

norru commented Dec 30, 2020

Attempted fix in #45

@Ralith Ralith closed this as completed in 9dbaa6f Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants