Commit aca3c55
committed
audio: kpb: cast operands to size_t before width-widening multiplies
Six multiplications in the key-phrase buffer compute their product at
32-bit width and only then assign it to a wider size_t result. If the
operands are large the overflow has already occurred before widening.
The KPB sizing math is partly driven by externally-influenced values
(cli->drain_req, the configured channel count, sampling frequency and
container width), so this is a real overflow surface rather than a
purely theoretical one.
Cast the leading operand to size_t in each expression so the whole
product is evaluated at the destination width:
- kpb_micselect_copy16/32(): loop bound samples_per_chan * in_channels
- kpb_init_draining(): drain_req and bytes_per_ms
- adjust_drain_interval(): pipeline_period
- validate_host_params(): bytes_per_ms
No functional change on in-range inputs; only the intermediate
arithmetic width changes.
Found-by: CodeQL 2.24.2 (codeql/cpp-queries cpp-security-extended),
rule cpp/integer-multiplication-cast-to-long. Run with
database build-mode=none over sof/src (host clang cannot target the
Xtensa production build), 867 files / 98 queries. Findings at
kpb.c:1117,1148,1610,1619,1791,2397.
AI-triaged: findings manually cross-referenced against
clang-tidy bugprone-implicit-widening-of-multiplication-result and
semgrep raptor-integer-truncation on the same surface, and confirmed
the operand types (uint32_t / macro constants) against
struct sof_kpb_config and struct kpb_client before fixing.
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>1 parent 0f9fa75 commit aca3c55
1 file changed
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | | - | |
| 1110 | + | |
1111 | 1111 | | |
1112 | 1112 | | |
1113 | 1113 | | |
| |||
1138 | 1138 | | |
1139 | 1139 | | |
1140 | 1140 | | |
1141 | | - | |
| 1141 | + | |
1142 | 1142 | | |
1143 | 1143 | | |
1144 | 1144 | | |
| |||
1607 | 1607 | | |
1608 | 1608 | | |
1609 | 1609 | | |
1610 | | - | |
| 1610 | + | |
1611 | 1611 | | |
1612 | 1612 | | |
1613 | 1613 | | |
| |||
1616 | 1616 | | |
1617 | 1617 | | |
1618 | 1618 | | |
1619 | | - | |
| 1619 | + | |
1620 | 1620 | | |
1621 | 1621 | | |
1622 | 1622 | | |
| |||
1788 | 1788 | | |
1789 | 1789 | | |
1790 | 1790 | | |
1791 | | - | |
| 1791 | + | |
1792 | 1792 | | |
1793 | 1793 | | |
1794 | 1794 | | |
| |||
2394 | 2394 | | |
2395 | 2395 | | |
2396 | 2396 | | |
2397 | | - | |
| 2397 | + | |
2398 | 2398 | | |
2399 | 2399 | | |
2400 | 2400 | | |
| |||
0 commit comments