Skip to content

[mod_silk] Bound decode loop to the codec's frame limit - #3116

Merged
andywolk merged 1 commit into
masterfrom
dmitry/fix_silk_decode
Aug 8, 2026
Merged

[mod_silk] Bound decode loop to the codec's frame limit#3116
andywolk merged 1 commit into
masterfrom
dmitry/fix_silk_decode

Conversation

@morbit85

@morbit85 morbit85 commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

switch_silk_decode() ran its do/while decode loop while the SDK kept reporting more internal frames, advancing the output pointer each pass with no cap. The destination is a fixed-size PCM buffer, so a stream reporting more internal frames than a conformant packet can carry let the accumulated write run past its end.

Stop after MAX_INPUT_FRAMES internal frames, the most a conformant SILK packet can hold, so the accumulated PCM stays within the destination regardless of the bitstream.

Declare the per-pass sample count inside the loop so it resets to zero each iteration, and advance the output pointer and length only when it is positive. A pass that writes no samples, including a tolerated FEC payload error that leaves the count untouched, then contributes nothing instead of advancing on a stale count from an earlier pass or on a negative value.

`switch_silk_decode()` ran its `do`/`while` decode loop while the SDK
kept reporting more internal frames, advancing the output pointer each
pass with no cap. The destination is a fixed-size PCM buffer, so a
stream reporting more internal frames than a conformant packet can
carry let the accumulated write run past its end.

Stop after `MAX_INPUT_FRAMES` internal frames, the most a conformant
SILK packet can hold, so the accumulated PCM stays within the
destination regardless of the bitstream.

Declare the per-pass sample count inside the loop so it resets to zero
each iteration, and advance the output pointer and length only when it
is positive. A pass that writes no samples, including a tolerated FEC
payload error that leaves the count untouched, then contributes nothing
instead of advancing on a stale count from an earlier pass or on a
negative value.
@morbit85
morbit85 requested a review from andywolk August 8, 2026 20:42
@morbit85 morbit85 added the bug Something isn't working label Aug 8, 2026
@andywolk
andywolk merged commit bc1e992 into master Aug 8, 2026
20 checks passed
@andywolk
andywolk deleted the dmitry/fix_silk_decode branch August 8, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants