fix: heap out-of-bounds read in log_mel_spectrogram on very short audio - #3956
Open
shafiuzzaman-md wants to merge 1 commit into
Open
fix: heap out-of-bounds read in log_mel_spectrogram on very short audio#3956shafiuzzaman-md wants to merge 1 commit into
shafiuzzaman-md wants to merge 1 commit into
Conversation
log_mel_spectrogram reflect-pads the start of the audio buffer by reading 200 samples from samples[1], with no check that the input has that many samples. Audio shorter than 201 samples reads past the end of `samples` (heap out-of-bounds read); the existing minimum-length check runs later, in whisper_full_with_state, after this access. Clamp the reflected count to the available input. Normal-length audio (n_samples >= 201) is unchanged.
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.
Problem
log_mel_spectrogramreflect-pads the start of the audio buffer by reading 200 samples starting atsamples[1], with no check that the input has that many samples:Any audio shorter than 201 samples (about 12.6 ms at 16 kHz) makes this read past the end of
samples.The existing "input is too short" minimum-length check runs later, in
whisper_full_with_state, only afterwhisper_pcm_to_mel_with_state(and therefore this read) has already executed, so it does not prevent theaccess.
Reproduced with a 5-sample (54-byte) WAV through the stock
whisper-cli, under an AddressSanitizer build:(Note: whisper.cpp's
-DWHISPER_SANITIZE_ADDRESS=ONonly instrumentsggml/, notsrc/, so ASan has tobe passed globally via
CMAKE_*_FLAGSto catch this.)Fix
Clamp the number of reflected samples to what is actually available. For normal-length audio
(
n_samples >= 201) this is identical to the previous behavior; for shorter input it reflects only theavailable samples and leaves the remaining leading pad as the zero-initialized value.
Testing
src/whisper.cpp:3201.message and returns cleanly (exit 0). Normal-length audio is unaffected.