Skip to content

Add check for malformed audio files#2225

Open
apsonawane wants to merge 4 commits into
mainfrom
asonawane/audio-decoder
Open

Add check for malformed audio files#2225
apsonawane wants to merge 4 commits into
mainfrom
asonawane/audio-decoder

Conversation

@apsonawane

@apsonawane apsonawane commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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

Copilot AI review requested due to automatic review settings June 12, 2026 05:19
@apsonawane apsonawane requested a review from a team as a code owner June 12, 2026 05:19
@apsonawane apsonawane enabled auto-merge (squash) June 12, 2026 05:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LoadAudiosFromBuffers to 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 OgaAudios is 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.

Comment thread src/models/processor.cpp Outdated
Comment thread src/models/processor.cpp Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this check to be more generic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants