Fix CY0 buffer overflow in beamformer working struct#91
Fix CY0 buffer overflow in beamformer working struct#91goyalpalak18 wants to merge 1 commit intoeembc:mainfrom
Conversation
CY0 was declared as NFFTD2*COMPLEX+2 (130 floats) but is used as a full-spectrum buffer for 128-point CFFT requiring 256 floats. Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
|
This PR fixes a buffer overflow in the beamformer where CY0 was declared using NFFTD2 (half size) but used as NFFT (full size) in the synthesis loop. This was causing a 504-byte write past the end of the array. I verified the fix with AddressSanitizer and confirmed that benchmark scores match the baseline. I’d appreciate a review when you get a chance. Happy to make any changes if needed. Thanks! |
|
Thanks the for pull request. We will review. |
|
Bug confirmed and the code changes have been review. I merged the PR into dev_20261q1 branch. |
|
@joseph-yiu ,thanks for confirming the bug and merging the fix into dev_20261q1 branch. Since the changes are merged, should I close this PR now or will it be closed automatically when that branch is merged to main? |
|
We can leave it open for now in case any reviewer have additional comments. We will close it when we merged it to the main. |
|
Understood, I'll leave it open. Thanks @joseph-yiu ! |
Summary
Identified and fixed a buffer overflow in the
CY0scratch buffer.The buffer was declared using the half-spectrum constant (
NFFTD2), but the synthesis logic treats it as full-spectrum (NFFT). This resulted in writing 126 floats (504 bytes) past the end of the array during the IFFT and spectrum extension stages.On the current ARM build, this overflow was overwriting the adjacent
XYstruct member. It did not trigger a crash solely due to the specific memory layout and the fact thatXYwas effectively unused at that point in the frame. This fix updatesCY0to the correct full-spectrum size to prevent the out-of-bounds writes.The Bug
The
CY0buffer was declared withNFFTD2(half-spectrum size), likely because it's used for some half-spectrum math early in the function.However, later in the synthesis stage (specifically the complex IFFT), we treat
CY0as a full-spectrum buffer. We end up writing about 126 floats past the end of the array.The Fix
I just bumped the size of
CY0to match the other full-spectrum buffers (mic,BM, etc).