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

Race condition in soundio_ring_buffer_fill_count #276

Open
krumelmonster opened this issue Apr 17, 2023 · 0 comments
Open

Race condition in soundio_ring_buffer_fill_count #276

krumelmonster opened this issue Apr 17, 2023 · 0 comments

Comments

@krumelmonster
Copy link

The soundio_ring_buffer_fill_count function is not thread safe. The read and write pointers may change inbetween the calls to SOUNDIO_ATOMIC_LOAD. In my case this leads to assertion failures at assert(count <= rb->capacity); randomly.

https://github.com/andrewrk/libsoundio/blob/master/src/ring_buffer.c#L72

Attached is a screenshot that shows how the assertion fires because an outdated read_offset value is used to calulate count, resulting in count=26521600-25850880=670720 which wrongfully indicates count exceeded the buffers capacity of 667648. If a synchronization primitive had prevented the pointers from being read while modified, count would have correctly been calculated as count=26521600-25861120=660480.

image

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