Skip to content

Commit 758eba9

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 758eba9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

tools/probes/probes_demux.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,17 @@ int init_wave(struct dma_frame_parser *p, uint32_t buffer_id, uint32_t format)
125125
p->files[i].header.fmt.subchunk_size = 16;
126126
p->files[i].header.fmt.audio_format = 1;
127127
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];
128+
/* the sample-rate field is 4 bits (0-15) but the table has fewer
129+
* entries; fall back to a valid default (48000 Hz) for an out-of-range
130+
* index so the read stays in bounds and the WAV header keeps a usable
131+
* rate
132+
*/
133+
uint32_t rate_idx = (format & PROBE_MASK_SAMPLE_RATE) >> PROBE_SHIFT_SAMPLE_RATE;
134+
135+
if (rate_idx >= sizeof(sample_rate) / sizeof(sample_rate[0]))
136+
p->files[i].header.fmt.sample_rate = 48000;
137+
else
138+
p->files[i].header.fmt.sample_rate = sample_rate[rate_idx];
129139
p->files[i].header.fmt.bits_per_sample = (((format & PROBE_MASK_CONTAINER_SIZE) >> PROBE_SHIFT_CONTAINER_SIZE) + 1) * 8;
130140
p->files[i].header.fmt.byte_rate = p->files[i].header.fmt.sample_rate *
131141
p->files[i].header.fmt.num_channels *

0 commit comments

Comments
 (0)