Fix: Add parameter magnitude validation in signal kernel Prepare functions#3594
Open
foodlook wants to merge 6 commits into
Open
Fix: Add parameter magnitude validation in signal kernel Prepare functions#3594foodlook wants to merge 6 commits into
foodlook wants to merge 6 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
TF_LITE_ENSUREmagnitude checks in 6 signal kernelPreparefunctions to prevent out-of-bounds memory access and divide-by-zero from crafted model parameters.Problem
Each signal kernel's
Preparevalidates tensor dimension count and type but never the dimension values or the relationship between op flexbuffer parameters and buffer sizes. A crafted.tflitemodel can set e.g.frame_step > frame_size,input_length > fft_length, orn_frames = 0, triggering heap-buffer-overflow or divide-by-zero inEval.All 7 sinks are dynamically proven with ASan/UBSan crashes on the real
signal/src/functions.Changes
overlap_add.ccframe_size>0,n_frames>0,frame_step>0,frame_step<=frame_sizerfft.ccfft_length>0,input_length>0,input_length<=fft_lengthenergy.ccstart_index>=0,end_index>start_index,end_index<=input_elemswindow.ccweight_size>0,input_size>0,input_size%weight_size==0, input==output sizefilter_bank_spectral_subtraction.ccnum_channels>0, matches input/output/noise dimspcan.ccinput_elems>0, matches noise_estimate/output dimsReferences
Testing
The fix adds early-return
kTfLiteErrorfor invalid parameters that previously caused undefined behavior. Existing tests should pass unchanged (they use valid parameters).