Skip to content

audio: copier: fix channel and memcpy validation#10897

Open
abonislawski wants to merge 2 commits into
thesofproject:mainfrom
abonislawski:fix/copier_set_gain_channels
Open

audio: copier: fix channel and memcpy validation#10897
abonislawski wants to merge 2 commits into
thesofproject:mainfrom
abonislawski:fix/copier_set_gain_channels

Conversation

@abonislawski

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 12, 2026 11:42
@abonislawski abonislawski requested a review from pblaszko as a code owner June 12, 2026 11:42
channels is host-controlled (8-bit, 0-255).
Without validation it drives the memcpy length (channels * sizeof(uint16_t))
against a MAX_GAIN_COEFFS_CNT-sized stack buffer and, for channels == 0,
causes divide-by-zero in the coefficient replication loop.
Reject values outside [1, MAX_GAIN_COEFFS_CNT].

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>

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.

Updates copier gain DMA control to use an unsigned channel count, adds explicit channel-count validation, and fixes memcpy_s destination size validation to prevent incorrect bounds checking.

Changes:

  • Switch channels parameter/type from int to uint32_t for copier gain configuration.
  • Add runtime validation for channels (non-zero and within MAX_GAIN_COEFFS_CNT).
  • Correct memcpy_s usage by passing the full destination buffer size.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/audio/copier/copier_gain.h Updates copier_set_gain() API to take uint32_t channels.
src/audio/copier/copier_gain.c Uses uint32_t channels, validates range, and fixes memcpy_s destination size argument.

Comment thread src/audio/copier/copier_gain.h
The first memcpy_s call passed gain_coef_size
(= channels * sizeof(uint16_t), host-controlled) as
the dest_size argument, defeating the bounds check.
Pass sizeof(static_gain) — the true buffer capacity
so memcpy_s can enforce the limit.

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
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.

3 participants