[raudio] Fixed buffer overflow when loading WAV files #4539
+2
−2
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 PR fixes a heap buffer overflow in raudio that can be triggered by a WAV file with a very large frame count. This is the result of two separate issues. The first is an integer overflow in the call to malloc since the unsigned integer can be overflowed when multiplied by the maximum number of channels (256). The second is using the 64-bit value for frame count even though it is cast to an unsigned int when allocating the buffer.
To fix this, I cast the frame count to a size_t in the malloc call, and I used 32-bit value for the number of frames to be written to the buffer. I recognize that issues like these aren't critical since the assets are almost always trusted, but it is nice to fix in case anyone wants to incorporate user-generated content into their game.