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

rt_linux: fix buffer_frames overflow panic #23

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

hinto-janai
Copy link
Contributor

promote_current_thread_to_real_time() will panic if:

  • The given audio_buffer_frames is 0 and audio_samplerate_hz is greater than 85_880 OR
  • The given audio_buffer_frames is 4295 or greater

Line 274 is where the multiplication overflow panic occurs.

let buffer_frames = if audio_buffer_frames > 0 {
audio_buffer_frames
} else {
// 50ms slice. This "ought to be enough for anybody".
audio_samplerate_hz / 20
};
let budget_us = (buffer_frames * 1_000_000 / audio_samplerate_hz) as u64;

For example, using a relatively normal input 0 (default) and 96,000Hz:

// This panics.
//
// This will eventually execute:
//   96_000 / 20 = 4800
//   4800 * 1_000_000 = 4_800_000_000
//
// which overflows `u32`.
audio_thread_priority::promote_current_thread_to_real_time(0, 96_000);

kinetiknz added a commit that referenced this pull request Nov 14, 2023
@kinetiknz kinetiknz merged commit 9b4b506 into mozilla:master Nov 14, 2023
8 of 12 checks passed
@kinetiknz
Copy link
Contributor

Thanks for this! Merged and added a simple test to avoid repeating this bug.

@hinto-janai hinto-janai deleted the overflow branch November 14, 2023 21:58
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