gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
272 stars 105 forks source link

glib: fix UB in VariantStrIter::impl_get #1343

Closed decathorpe closed 3 months ago

decathorpe commented 3 months ago

Passing an immutable reference (&p) to a function that mutates the data behind the pointer violates Rust's invariants.

This causes multiple tests in the test suite to crash when compiling it with optimizations (either --release mode or with opt-level of 2 or 3) with recent Rust versions, which is easy to reproduce, especially with nightly Rust:

$ cargo +nightly test --release --package glib
(...)
error: test failed, to rerun pass `--lib`
Caused by:
  process didn't exit successfully: (...) (signal: 11, SIGSEGV: invalid memory reference)

Looks like this wasn't caught earlier because the wrapped C function is variadic and there's less type checking happening because of that.

sdroege commented 3 months ago

Thanks!