-
Notifications
You must be signed in to change notification settings - Fork 4
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
Undefined behaviour in vorbis_rs #22
Comments
Hello, thank you so much for reporting this issue! I was not aware of the consequences of pointer aliasing in the context of
Therefore, I addressed the undefined behavior in question in this commit by modifying the code to bail out of To validate this approach, I adapted your reduced playground example using the same fix and successfully tested it with Miri. I'd greatly appreciate if you could review the changes in the referenced commit to confirm whether the fix looks good to you as well, just to make sure I haven't missed any other thing 😇 |
Thanks! I will check out the commits when I get the time. |
Hi! In vorbis_rs, the encoder state is created with
vorbis_info
,vorbis_dsp_state
, andvorbis_block
all owned by theVorbisEncodingState
object, but with pointers pointing to one another.vorbis-rs/packages/vorbis_rs/src/encoder/encoder_util.rs
Lines 20 to 50 in c01a3ea
https://github.com/ComunidadAylas/vorbis-aotuv-lancer/blob/1c49413115971752e360025af58f0e418106e7b9/lib/block.c#L84-L107
Then mutation is performed using such pointers rather than through those owner references or references/pointers derived from them:
https://github.com/ComunidadAylas/vorbis-aotuv-lancer/blob/1c49413115971752e360025af58f0e418106e7b9/lib/analysis.c#L40
This is an undefined behaviour and may cause miscompilation. A simplified demo https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=a98129c85a837c05db5958f33c24fe18 shows different results under debug and release. MIRI can catch this issue in the simplified demo but unfortunately does not work for the original code because it does not support FFI.
The text was updated successfully, but these errors were encountered: