Skip to content

Commit a467602

Browse files
committed
audio: kpb: widen channel loop counter to match micsel_channels
The four kpb_micselect_copy16/32() variants declare the channel loop counter "ch" as uint16_t while iterating "for (ch = 0; ch < ... micsel_channels; ch++)", where micsel_channels is uint32_t. The loop condition promotes ch to a wider type for the comparison, so if micsel_channels ever exceeds UINT16_MAX the counter wraps at 65536 and the loop fails to terminate. The same narrow counter would also truncate channel indexing. Declare ch as uint32_t so its width matches the bound it is compared against and the channel count it indexes. KPB_MAX_MICSEL_CHANNELS keeps the real value small, so this is hardening rather than an observed runaway, but the type mismatch is removed at the source. CodeQL flagged the two non-HiFi variants (kpb.c:1112,1143); the two KPB_HIFI3 variants (kpb.c:1050,1084) carry the identical pattern and are fixed in the same change for consistency. Found-by: CodeQL 2.24.2 (codeql/cpp-queries cpp-security-extended), rule cpp/comparison-with-wider-type. Run with database build-mode=none over sof/src, 867 files / 98 queries. AI-triaged: traced ch and micsel_channels declarations across all four micselect copy functions and confirmed the bound is uint32_t before widening the counter; extended the fix to the HiFi3 variants the tool did not reach in this build configuration. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
1 parent aca3c55 commit a467602

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/audio/kpb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static void kpb_micselect_copy16(struct comp_buffer *sink,
10331033
{
10341034
struct audio_stream *istream = &source->stream;
10351035
struct audio_stream *ostream = &sink->stream;
1036-
uint16_t ch;
1036+
uint32_t ch;
10371037
size_t i;
10381038

10391039
AE_SETCBEGIN0(audio_stream_get_addr(ostream));
@@ -1066,7 +1066,7 @@ static void kpb_micselect_copy32(struct comp_buffer *sink,
10661066
{
10671067
struct audio_stream *istream = &source->stream;
10681068
struct audio_stream *ostream = &sink->stream;
1069-
uint16_t ch;
1069+
uint32_t ch;
10701070
size_t i;
10711071

10721072
AE_SETCBEGIN0(audio_stream_get_addr(ostream));
@@ -1103,7 +1103,7 @@ static void kpb_micselect_copy16(struct comp_buffer *sink,
11031103

11041104
buffer_stream_invalidate(source, size);
11051105
size_t out_samples;
1106-
uint16_t ch;
1106+
uint32_t ch;
11071107

11081108
const int16_t *in_data;
11091109
int16_t *out_data;
@@ -1135,7 +1135,7 @@ static void kpb_micselect_copy32(struct comp_buffer *sink,
11351135

11361136
buffer_stream_invalidate(source, size);
11371137
size_t out_samples;
1138-
uint16_t ch;
1138+
uint32_t ch;
11391139
const int32_t *in_data;
11401140
int32_t *out_data;
11411141
const size_t samples_per_chan = size / (sizeof(uint32_t) * micsel_channels);

0 commit comments

Comments
 (0)