Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsound behavior on impl DerefMut #170

Open
TroyKomodo opened this issue Jan 3, 2024 · 0 comments
Open

Unsound behavior on impl DerefMut #170

TroyKomodo opened this issue Jan 3, 2024 · 0 comments

Comments

@TroyKomodo
Copy link

TroyKomodo commented Jan 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant