Add check for malformed audio files - #1079
Merged
Merged
Conversation
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
June 12, 2026 05:20
View session
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
June 12, 2026 05:20
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the speech feature-extraction pipeline against malformed/degenerate audio inputs by adding runtime validation in LogMel::Compute and introducing regression tests intended to prevent prior crash/OOB-read scenarios.
Changes:
- Replaced a debug-only
assertinLogMel::Computewith runtime shape validation and added a guard against degenerate STFT outputs. - Added new regression tests around malformed audio inputs to ensure failures are handled gracefully.
- Updated test includes to support feature-extractor-based testing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
test/pp_api_test/test_decode_audio.cc |
Adds regression tests intended to ensure malformed audio does not crash decode/extraction paths. |
shared/api/speech_features.hpp |
Adds input validation to LogMel::Compute to reject invalid shapes and degenerate STFT outputs before unsafe operations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
kunal-vaishnavi
approved these changes
Jun 12, 2026
Akshay Sonawane (apsonawane)
added a commit
to microsoft/onnxruntime-genai
that referenced
this pull request
Jun 30, 2026
This pull request improves the robustness of audio buffer handling by adding a minimum size check for audio data and introduces a regression test to ensure malformed buffers are properly rejected. These changes prevent crashes due to undersized or malformed audio buffers and improve error reporting. **Audio buffer validation:** * Added a minimum buffer size check (`kMinAudioBufferSize = 44`) in `LoadAudiosFromBuffers` to reject audio buffers that are too small to contain a valid audio header, throwing a clear runtime error if violated. **Testing improvements:** * Added a regression test (`LoadAudiosFromBuffersRejectsTooSmallBuffer`) to ensure that audio buffers smaller than the minimum required size are rejected with a descriptive error, preventing heap-buffer-overflow crashes. Onnxruntime-extensions validation check: microsoft/onnxruntime-extensions#1079
Tianlei Wu (tianleiwu)
pushed a commit
to microsoft/onnxruntime-genai
that referenced
this pull request
Jul 11, 2026
This pull request improves the robustness of audio buffer handling by adding a minimum size check for audio data and introduces a regression test to ensure malformed buffers are properly rejected. These changes prevent crashes due to undersized or malformed audio buffers and improve error reporting. **Audio buffer validation:** * Added a minimum buffer size check (`kMinAudioBufferSize = 44`) in `LoadAudiosFromBuffers` to reject audio buffers that are too small to contain a valid audio header, throwing a clear runtime error if violated. **Testing improvements:** * Added a regression test (`LoadAudiosFromBuffersRejectsTooSmallBuffer`) to ensure that audio buffers smaller than the minimum required size are rejected with a descriptive error, preventing heap-buffer-overflow crashes. Onnxruntime-extensions validation check: microsoft/onnxruntime-extensions#1079
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.
This pull request improves the robustness of the LogMel feature extraction by adding input validation and new regression tests to handle malformed audio data that previously could cause crashes or out-of-bounds reads. The main focus is on ensuring that degenerate or malformed input data is detected early and handled gracefully, preventing potential heap-buffer-overflow errors.
Input validation and error handling:
LogMel::Computemethod to check the input tensor shape and reject degenerate spectrograms (e.g., too few time steps or frequency bins), returning a clear error instead of asserting or crashing.Testing and regression coverage:
MalformedAudioDoesNotCrash) to verify that decoding malformed audio data fails gracefully without crashing, addressing a previously reported heap-buffer-overflow issue.MalformedAudioLogMelDoesNotCrash) to ensure the LogMel feature extractor rejects malformed audio that produces a degenerate spectrogram, rather than crashing.shared/api/speech_extractor.hheader in the test file to support the new tests.Onnxruntime-genai validation check: microsoft/onnxruntime-genai#2225