Skip to content

Commit e04a72c

Browse files
committed
tools/probe: clamp out-of-range sample-rate index to a valid default
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>
1 parent 3f7738d commit e04a72c

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

tools/probes/probes_demux.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ static uint32_t sample_rate[] = {
5959
48000, 64000, 88200, 96000, 128000, 176400, 192000
6060
};
6161

62+
/* fallback index (48000 Hz) used when the probe's 4-bit rate field is out of
63+
* range, so the generated WAV header keeps a valid sample rate
64+
*/
65+
#define PROBE_DEFAULT_RATE_IDX 8
66+
6267
int get_buffer_file(struct wave_files *files, uint32_t buffer_id)
6368
{
6469
int i;
@@ -125,7 +130,16 @@ int init_wave(struct dma_frame_parser *p, uint32_t buffer_id, uint32_t format)
125130
p->files[i].header.fmt.subchunk_size = 16;
126131
p->files[i].header.fmt.audio_format = 1;
127132
p->files[i].header.fmt.num_channels = ((format & PROBE_MASK_NB_CHANNELS) >> PROBE_SHIFT_NB_CHANNELS) + 1;
128-
p->files[i].header.fmt.sample_rate = sample_rate[(format & PROBE_MASK_SAMPLE_RATE) >> PROBE_SHIFT_SAMPLE_RATE];
133+
/* the sample-rate field is 4 bits (0-15) but the table has fewer
134+
* entries; clamp an out-of-range index to a valid default so the read
135+
* stays in bounds and the WAV header keeps a usable rate
136+
*/
137+
uint32_t rate_idx = (format & PROBE_MASK_SAMPLE_RATE) >> PROBE_SHIFT_SAMPLE_RATE;
138+
139+
if (rate_idx >= sizeof(sample_rate) / sizeof(sample_rate[0]))
140+
rate_idx = PROBE_DEFAULT_RATE_IDX;
141+
142+
p->files[i].header.fmt.sample_rate = sample_rate[rate_idx];
129143
p->files[i].header.fmt.bits_per_sample = (((format & PROBE_MASK_CONTAINER_SIZE) >> PROBE_SHIFT_CONTAINER_SIZE) + 1) * 8;
130144
p->files[i].header.fmt.byte_rate = p->files[i].header.fmt.sample_rate *
131145
p->files[i].header.fmt.num_channels *

0 commit comments

Comments
 (0)