Open Seb-degraff opened 8 months ago
This is weird - I don't see how y&255
(with int y
) should be undefined behavior, or return negative results. Regardless of the value of y
, it should return a value between 0
and 255
. Is it possible that your compiler has a bug?
(and FWIW, on my Linux amd64 system, with clang 14, your repro always says Files matched!
- of course there could be platform-specific differences to ARM64 and/or Mac, but as I wrote, I don't see how the original code could possibly be wrong)
Oh interesting! Thank you for looking into it. I’ll do more testing on my side
Fixes distorted decompressed audio when UBSan was enabled.
I found an audio distortion issue while working on a game. This bug seems petty harmless since it shows up only when ubsan is enabled (for me at least). However – since I was not listening to audio at the time at enabled ubsan – it took me a little while to link the audio distortion bug to the fact that ubsan was enabled. Fixing this might save others the trouble!
Distorted audio (ubsan enabled): https://github.com/nothings/stb/assets/6556843/a92daa96-4ac0-4c3f-aa03-4e58d161dd78 Correct audio (ubsan disabled): https://github.com/nothings/stb/assets/6556843/a932be22-d25d-4158-8f16-e3effc583416
Minimal repro: stb_vorbis_ubsan_bug_repro.zip
Running run_repro.sh on my arm mac results in this input showing that the decoded data with and without ubsan don't match: