Skip to content

Commit

Permalink
Fix array out-of-bounds access in WideDynamicFuncLut (#2468)
Browse files Browse the repository at this point in the history
### Problem description:

In the original code, pointer arithmetic of gain_lut and the assignment of gain_lut[4 * interval + 3] could potentially lead to out-of-bounds array access.
On certain architectures (e.g., macOS ARM64), this out-of-bounds access causes the program to crash.
BUG=None, reported issue#2464

### Solution:

Increase the size of the gain_lut_storage array by 1 to provide an extra buffer and prevent overflow during the calculation within the loop.

### Risks and considerations:

Increasing the array size will slightly increase memory usage.
In extremely resource-constrained systems, alternative algorithm implementations may need to be considered.
  • Loading branch information
kismeter authored Feb 24, 2024
1 parent 8085cec commit cfa4c91
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ int16_t PcanGainLookupFunction(const float strength, const float offset,

py::list WideDynamicFuncLut(float strength, float offset, int input_bits,
int gain_bits) {
int16_t gain_lut_storage[kWideDynamicFunctionLUTSize];
// Avoid accessing outside of the buffer below gain_lut[4 * interval + 3].
int16_t gain_lut_storage[kWideDynamicFunctionLUTSize + 1];
int16_t* gain_lut = gain_lut_storage;

gain_lut[0] =
Expand Down

0 comments on commit cfa4c91

Please sign in to comment.