Conversation
There was a problem hiding this comment.
2 issues found across 1 file
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="src/syscall_sdl.c">
<violation number="1" location="src/syscall_sdl.c:857">
P1: Validate `sfx_data_size` against a reasonable maximum before allocating. The new code removes the previous fixed-size bound, so a large or malformed size from guest memory can cause huge allocations or overflow.</violation>
<violation number="2" location="src/syscall_sdl.c:938">
P1: Validate `music_data_size` against a maximum before allocating. The new heap allocation removes the previous upper bound, so malformed sizes can lead to excessive allocation or overflow.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
This replaces stack-local buffers with heap allocation for audio threads to eliminate use-after-free when threads outlive the calling function. - play_sfx/play_music: heap-allocate sound_t + data buffer together - sfx_handler/music_handler: take ownership and free argument - Use detached thread for native (non-blocking), joinable for EMSCRIPTEN - Handle pthread_create failure by freeing allocation - music_handler: free previous mid/music_midi_data to prevent leak - shutdown_audio: stop playback first, proper resource cleanup - Fix EMSCRIPTEN double-join by not setting init flags after immediate join - Validate size bounds before allocation to prevent DoS from guest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces stack-local buffers with heap allocation for audio threads to eliminate use-after-free when threads outlive the calling function.
Summary by cubic
Fixes a use-after-free in SDL audio by moving sfx/music buffers to the heap and giving handler threads ownership of their data. Playback is now stable across native and EMSCRIPTEN, with proper cleanup and fewer leaks.
Bug Fixes
Refactors
Written for commit dddf65d. Summary will update on new commits.