rust-mobile/android-activity

panic on nightly: `from_raw_parts` safety contract violation

skibon02 opened this issue · 0 comments

On latest nightly build my application fall into panic even before main function starts.
After figuring out, the problem was in file glue.rs:

unsafe { std::slice::from_raw_parts(saved_state_in as *const u8, saved_state_size) };

here, the saved_state_in is null in my case, which makes this operation violating safety contract.

To reproduce, create any minimal application with empty android_main function with native-activity feature.

Potentially, game activity code also have this issue, but wasn't tested

Panic message:

--------- beginning of crash
F/libc    ( 2629): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 2629 (penxr_framework), pid 2629 (penxr_framework)
I/RustStdoutStderr( 2629): thread '<unnamed>' panicked at library/core/src/panicking.rs:155:5:
I/RustStdoutStderr( 2629): unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
I/RustStdoutStderr( 2629): note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I/RustStdoutStderr( 2629): thread caused non-unwinding panic. aborting.