rust-ffmpeg icon indicating copy to clipboard operation
rust-ffmpeg copied to clipboard

Unsound behavior on impl DerefMut

Open TroyKomodo opened this issue 6 months ago • 0 comments

Please include as much info as possible to save me (solo maintainer helping for free) some time. A minimal, complete, and reproducible example is a must. Link to a gist if you don't feel like posting all the code inline. At the same time, please leave out unnecessary code so I don't need to wade through a hundred lines to get to the problematic part. Tell me your OS, FFmpeg version, etc. if there's even a slim chance of relevancy.

let mut i = ffmpeg_next::format::input(&"video.mp4").unwrap();
let mut i2 = ffmpeg_next::format::input(&"video.mp4").unwrap();
std::mem::swap(&mut *i, &mut *i2);
drop(i2);

println!("still alive");

println!("{}", i.format().name())
still alive
thread 'main' panicked at /home/troy/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ffmpeg-next-6.1.0/src/format/format/input.rs:26:53:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x75e8a3e2869450e7
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
[1]    190166 IOT instruction (core dumped)  cargo run

I suppose the only way to fix this is to not use deref mut and just expose the methods via impl using deref mut allows users to swap the inner values and can cause strange issues. Obviously people SHOULD not be doing this but they can.

Not sure what to think / do about this.

TroyKomodo avatar Jan 03 '24 06:01 TroyKomodo