Skip to content

math: auditory: guard mod_psy_get_mel_filterbank() against zero divisors#10916

Open
singalsu wants to merge 1 commit into
thesofproject:mainfrom
singalsu:auditory_updates
Open

math: auditory: guard mod_psy_get_mel_filterbank() against zero divisors#10916
singalsu wants to merge 1 commit into
thesofproject:mainfrom
singalsu:auditory_updates

Conversation

@singalsu

Copy link
Copy Markdown
Collaborator

The mel-bin loop in mod_psy_get_mel_filterbank() divides by delta_cl and delta_rc on every FFT bin, and by (right_hz - left_hz) when slaney normalization is enabled. With unusual configurations these denominators can become zero or negative — for example when start_freq >= end_freq, when the requested mel_bins is large enough that integer division truncates the mel step to zero, or at extreme inputs where psy_mel_to_hz saturates and right_hz no longer exceeds left_hz.

Reject such configurations explicitly. After computing mel_step, return -EINVAL if it is not positive, which also covers both delta values since they equal mel_step. In the slaney_normalize branch, also verify right_hz > left_hz before computing the scale factor.

@singalsu singalsu marked this pull request as ready for review June 15, 2026 11:35
Copilot AI review requested due to automatic review settings June 15, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds explicit validation in mod_psy_get_mel_filterbank() to prevent division-by-zero/invalid range calculations under unusual mel filterbank configurations.

Changes:

  • Reject non-positive mel_step configurations before using it as a divisor.
  • Reject Slaney-normalization bins where right_hz <= left_hz before computing the scale factor.

Comment thread src/math/auditory/auditory.c
Comment thread src/math/auditory/auditory.c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/math/auditory/auditory.c
Comment on lines 173 to 175
for (i = 0; i < fb->mel_bins; i++) {
left_mel = mel_start + i * mel_step;
center_mel = mel_start + (i + 1) * mel_step;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't do, not relevant.

Comment thread src/math/auditory/auditory.c
The mel-bin loop in mod_psy_get_mel_filterbank() divides by delta_cl and
delta_rc on every FFT bin, and by (right_hz - left_hz) when slaney
normalization is enabled. With unusual configurations these denominators
can become zero or negative — for example when start_freq >= end_freq,
when the requested mel_bins is large enough that integer division
truncates the mel step to zero, or at extreme inputs where psy_mel_to_hz
saturates and right_hz no longer exceeds left_hz.

Reject such configurations explicitly. After computing mel_step, return
-EINVAL if it is not positive, which also covers both delta values
since they equal mel_step. In the slaney_normalize branch, also verify
right_hz > left_hz before computing the scale factor.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>

@jsarha jsarha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@singalsu

Copy link
Copy Markdown
Collaborator Author

The quickbuild fails 1) for MTL Test HDA passthrough compress data 2) PTL HDA link random DMA are not related to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants