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: possible integer overflow #35

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

Conversation

b4yuan
Copy link

@b4yuan b4yuan commented Jun 20, 2023

If user input is large enough, the multiplication to calculate malloc() size could overflow.

@@ -112,7 +112,7 @@ int load_wav(float* signal, int* num_samples, int* sample_rate, const char* path
*num_samples = subChunk2Size / blockAlign;
*sample_rate = sampleRate;

int16_t* raw_data = (int16_t*)malloc(*num_samples * blockAlign);
int16_t* raw_data = (int16_t*)calloc(*num_samples * blockAlign);
Copy link

Choose a reason for hiding this comment

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

Should be calloc(*num_samples, blockAlign)

@@ -25,7 +25,7 @@ void save_wav(const float* signal, int num_samples, int sample_rate, const char*
uint32_t chunkSize = 4 + (8 + subChunk1Size) + (8 + subChunk2Size);
char format[4] = { 'W', 'A', 'V', 'E' };

int16_t* raw_data = (int16_t*)malloc(num_samples * blockAlign);
int16_t* raw_data = (int16_t*)malloc((int16_t) num_samples * blockAlign);
Copy link

Choose a reason for hiding this comment

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

Should be calloc(num_samples, blockAlign)

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