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

Implement seek for missing codes in wavestream #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lakor64
Copy link

@lakor64 lakor64 commented Dec 25, 2021

The following code implements seeking for WAV, FLAC and MP3 on the . This also fixes looping on those three file types when enabled.

By looking on the offset code on OGG (with stb_vorbis_get_sample_offset), I am not sure if it's required on dr* libraries as it doesn't seem to jump to a different PCM, I guess stb_vorbis_get_sample_offsets gets the position that we seek?

@HailToDodongo
Copy link

@jarikomppa
This PR actually fixes a pretty serious memory corruption issue i was facing in my project.
I traced this bug down with valgrind, where this exact function (WavStreamInstance::seek) was always the root-cause of invalid memory writes.

Before, this code only checked for mCodec.mOgg != nullptr and then assumed that the codec is ogg-vorbis.
However mCodec is a union, so every type (including wave) will have mCodec.mOgg set.
This causes stb_vorbis_get_sample_offset (treating *mWav's value as *mOgg) to write to arbitrary memory, which in my case lead to a crash.
Writes where also wide-spread, since the struct contains channel- and sample-counts which potentially became pretty large numbers.

After applying this patch, all other related OOB writes also vanished.
#279 seems to be related to this, since i got the exact same behaviour of null-pointers in that array.
This stopped too after that change.

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

Successfully merging this pull request may close these issues.

None yet

2 participants