Skip to content

Commit 6adec5b

Browse files
committed
audio: mfcc: Add frame_shift validation to prevent division by zero
Add input validation for the frame_shift configuration field in mfcc_setup(). A zero or negative value would cause a division by zero during STFT processing. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 1f32181 commit 6adec5b

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/audio/mfcc/mfcc_setup.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
155155
state->emph.coef = -config->preemphasis_coefficient; /* Negate config parameter */
156156
fft->fft_size = config->frame_length;
157157
fft->fft_padded_size = 1 << (31 - norm_int32(fft->fft_size)); /* Round up to nearest 2^N */
158+
/* frame_shift is the hop size and must be a positive value no larger
159+
* than the frame/FFT length, otherwise prev_data_size below underflows
160+
*/
161+
if (config->frame_shift <= 0 || config->frame_shift > config->frame_length) {
162+
comp_err(dev, "invalid frame_shift %d for frame_length %d",
163+
config->frame_shift, config->frame_length);
164+
return -EINVAL;
165+
}
158166
fft->fft_hop_size = config->frame_shift;
159167
fft->half_fft_size = (fft->fft_padded_size >> 1) + 1;
160168

0 commit comments

Comments
 (0)