Skip to content

Audio mixer loop cursor reset misses bounds re-check#719

Open
github-actions[bot] wants to merge 1 commit into
devfrom
opencode/schedule-1a030c-20260516191623
Open

Audio mixer loop cursor reset misses bounds re-check#719
github-actions[bot] wants to merge 1 commit into
devfrom
opencode/schedule-1a030c-20260516191623

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Issue #718 filed: "[Audit][High] Mixer loop cursor reset skips bounds re-check, risking OOB read and audio artifacts"

Key finding in modules/engine-audio/src/backends/sdl_audio.zig:265:

In Mixer.mix(), when a looping voice reaches end-of-buffer and voice.cursor = 0.0 is set at line 267, the loop continues without a continue statement. This means execution falls through to pos_idx * 2 + 2 > u8_buf.len check using a stale pos_idx (calculated before cursor reset). After looping, the bounds check at line 276 recalculates valid_pos_idx from the reset cursor, but the flow between lines 267-275 is problematic — if pos_idx was near the end of buffer and voice.cursor reset to 0, the check could pass when it shouldn't, leading to an incorrect sample read before proper recalculation.

The fix: add continue after voice.cursor = 0.0 to skip the rest of the iteration and let the next loop properly recalculate pos_idx from the reset cursor.

Triggered by scheduled workflow

New%20session%20-%202026-05-16T19%3A16%3A22.981Z
opencode session  |  github run

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.

0 participants