rust-mobile / android-activity

Glue for building Rust applications on Android with NativeActivity or GameActivity
238 stars 46 forks source link

panic on nightly: `from_raw_parts` safety contract violation #153

Closed skibon02 closed 4 months ago

skibon02 commented 7 months ago

On latest nightly build my application fall into panic even before main function starts. After figuring out, the problem was in file glue.rs: https://github.com/rust-mobile/android-activity/blob/c9faa9c44e04152863cc0ea9b6982065e0346ba6/android-activity/src/native_activity/glue.rs#L341

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.