Fix KWS NODE_MEMREQ instance header underallocation#95
Fix KWS NODE_MEMREQ instance header underallocation#95goyalpalak18 wants to merge 1 commit intoeembc:mainfrom
Conversation
Signed-off-by: goyalpalak18 <goyalpalak1806@gmail.com>
|
Hey @llefaucheur @joseph-yiu, could you take a look at this when you have a chance? Thanks! |
|
Hi @llefaucheur , could you confirm if you have reviewed this PR? Thanks :-) |
|
This "+ 8" is VERY bad indeed. Thank you Goyal for finding the bug ! PS: audiomark served as a proof-of-concept for another project ("NanoGraph") and instead of sharing hard constants like this, the "nodes" of the graph have memory banks allocated in "manifest files". Dynamic memory allocation is still possible but not recommended for embedded devices (especially the ones with very small memory) |
|
Thanks @llefaucheur for confirming. I have merged this into dev branch (dev_2026q1) and will close this PR when we merge the dev branch into main. |
|
Closing this pull request as the AudioMark v1.0.4 release is completed. |
While looking at the recent ABF memory patch (commit edc44cf), I noticed the exact same under-allocation bug exists in the KWS component.
The Bug
In
src/ee_kws.c,NODE_MEMREQallocates memory using a magic number:sizeof(mfcc_instance_t) + 8. The+ 8was probably meant to cover two 32-bit pointers, but it ignores thechunk_idxfield entirely and breaks on 64-bit platforms (where pointers are 8 bytes). There's literally a/* TODO : justift this */comment sitting right next to it.Because of this, the
kws_instance_tstruct overflows its heap block. This eats into the 12-byte CMSIS vectorized-read safety padding, leading to undefined behavior. On 64-bit RISC-V evaluation targets, this overflow can silently corrupt heap metadata or cause sliding window drifts that completely invalidate benchmark scores.The Fix
I mirrored the ABF fix by replacing the manual calculation with a standard
sizeof(kws_instance_t). Since the struct already includesmfcc_instance_tas its first member, this naturally accounts for all pointers,chunk_idx, and any compiler-inserted alignment padding across all architectures and pointer widths.This restores the full CMSIS 12-byte guard padding, eliminates the undefined behavior risk, and brings KWS up to the same correctness baseline as ABF.