Skip to content

fix: possible integer overflow#35

Open
b4yuan wants to merge 1 commit intokgoba:masterfrom
IVOES:cpp/uncontrolled-allocation-size
Open

fix: possible integer overflow#35
b4yuan wants to merge 1 commit intokgoba:masterfrom
IVOES:cpp/uncontrolled-allocation-size

Conversation

@b4yuan
Copy link
Copy Markdown

@b4yuan b4yuan commented Jun 20, 2023

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

Comment thread common/wave.c
*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
Copy Markdown

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)

Comment thread common/wave.c
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
Copy Markdown

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.

2 participants