Add check for malformed audio files#2225
Open
apsonawane wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves robustness of audio loading from in-memory buffers by adding a minimum-size guard in the core audio buffer loader, and adds a C API regression test to ensure undersized/malformed buffers are rejected with a clear error instead of crashing.
Changes:
- Add a minimum audio buffer size check in
LoadAudiosFromBuffersto reject trivially undersized inputs early. - Add a C API regression test that passes an undersized malformed buffer and asserts an error is returned (and no
OgaAudiosis produced).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/models/processor.cpp |
Adds a defensive minimum-size check before calling into the ORT extensions raw-audio creation path. |
test/c_api_tests.cpp |
Adds a regression test validating the C API rejects undersized audio buffers with an error. |
| throw std::runtime_error("Number of audio data buffers does not match the number of audio data sizes"); | ||
|
|
||
| // Conservative minimum buffer size to avoid decoder header parsing reading past the end of the buffer. | ||
| // 44 bytes matches the standard WAV header size; this is a safety check, not full format validation. |
Contributor
There was a problem hiding this comment.
This is too WAV-specific. The API supports other audio file types so a generic sanity check such as > 0 may be better. Otherwise, valid inputs may be rejected.
Contributor
Author
There was a problem hiding this comment.
Updated this check to be more generic
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 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:
kMinAudioBufferSize = 44) inLoadAudiosFromBuffersto reject audio buffers that are too small to contain a valid audio header, throwing a clear runtime error if violated.Testing improvements:
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