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

Fix undefined memcpy in AudioStreamWAV::get_data() #97790

Closed
wants to merge 1 commit into from

Conversation

jman168
Copy link
Contributor

@jman168 jman168 commented Oct 3, 2024

Fixes #97720. In the get_data() function of the AudioStreamWAV, memcpy is called on an undefined pointer due to assuming there is data after some padding bytes (which isn't true for an empty buffer). This was fixed by checking if there is actually any data to copy instead of checking if the buffer (including padding) is not empty (which should never be true).

@jman168 jman168 requested a review from a team as a code owner October 3, 2024 21:56
@Chaosus Chaosus added this to the 4.4 milestone Oct 4, 2024
@adamscott adamscott self-assigned this Oct 4, 2024
@AThousandShips AThousandShips added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Dec 15, 2024
Copy link
Member

@hpvb hpvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally okay. The problem appears to be that calling memcpy() with a dest of 0 causes a corruption even if size is 0. The src ptr while potentially invalid probably isn't because the LocalVector grows in power of two sizes.

@@ -584,7 +584,7 @@ void AudioStreamWAV::set_data(const Vector<uint8_t> &p_data) {
Vector<uint8_t> AudioStreamWAV::get_data() const {
Vector<uint8_t> pv;

if (!data.is_empty()) {
if (data_bytes != 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The surrounding code uses if (x) this should probably be changed to match.

@adamscott adamscott changed the title Fix undefined memcpy in AudioStreamWAV::get_data() Fix undefined memcpy in AudioStreamWAV::get_data() Dec 17, 2024
@akien-mga
Copy link
Member

akien-mga commented Dec 17, 2024

Superseded by #100422 (mostly for the impressive writeup which is worth merging for the legacy), but we've added you as co-author to that PR since you independently came up with the same fix.

Apologies for not reviewing it in time, while it was obviously correct in hindsight. Thanks for the contribution!

@akien-mga akien-mga closed this Dec 17, 2024
@akien-mga akien-mga added archived and removed cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Dec 17, 2024
@akien-mga akien-mga removed this from the 4.4 milestone Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The AudioStreamWav unit test seg faults
6 participants