probes: bound sample-rate index to the table size#10884
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens sof-probes WAV header generation by preventing out-of-bounds access when decoding the 4-bit sample-rate index from the probe format field.
Changes:
- Adds bounds checking for the sample-rate table index derived from the probe
formatfield. - Introduces a local
rate_idxvariable and conditional selection to avoid reading pastsample_rate[].
| uint32_t rate_idx = (format & PROBE_MASK_SAMPLE_RATE) >> PROBE_SHIFT_SAMPLE_RATE; | ||
|
|
||
| p->files[i].header.fmt.sample_rate = | ||
| rate_idx < sizeof(sample_rate) / sizeof(sample_rate[0]) ? | ||
| sample_rate[rate_idx] : 0; |
There was a problem hiding this comment.
Fixed — an out-of-range index now falls back to a valid 48000 Hz rate (per lyakh's suggestion) rather than 0, so the WAV header stays usable, and the code genuinely clamps now.
kv2019i
left a comment
There was a problem hiding this comment.
Commit message is off for this as well. And also copilot comment is good, better to set default to a valid rate.
We need a CLAUDE.md here, I'm wondering if we have single workflows and just use soft links with each agents name. |
| if (rate_idx >= sizeof(sample_rate) / sizeof(sample_rate[0])) | ||
| rate_idx = PROBE_DEFAULT_RATE_IDX; | ||
|
|
||
| p->files[i].header.fmt.sample_rate = sample_rate[rate_idx]; |
There was a problem hiding this comment.
in fact I think this would be better:
if (rate_idx >= sizeof(sample_rate) / sizeof(sample_rate[0]))
p->files[i].header.fmt.sample_rate = 48000;
else
p->files[i].header.fmt.sample_rate = sample_rate[rate_idx];
There was a problem hiding this comment.
Adopted — thanks, that's cleaner. Done: out-of-range now sets the rate directly to 48000 instead of going through a default-index macro. Force-pushed.
sorry, changed my mind, I think there's a simple nice way to avoid the manually managed default rate index
Every agent will support our single AGENTS.md except ...Claude. They are probably the last ones waiting to adapt the standard md name. |
The 4-bit sample-rate field can select an index past the end of the sample_rate[] table, which has fewer than 16 entries, reading out of bounds. Clamp an out-of-range index to a valid default rate (48000 Hz) so the read stays in bounds and the generated WAV header keeps a usable sample rate. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The four-bit sample-rate field could select an index past the rate table, which has fewer entries. Bound the index against the table size.