Fix AudioResampler crash on empty buffer input#8364
Open
struktured wants to merge 1 commit into
Open
Conversation
libsamplerate's src_process() throws when SRC_DATA->data_in or data_out
is null. An empty std::span yields data() == nullptr, so any caller
that hands process() a zero-frame view (e.g. a fully-consumed buffer
slice in Sf2Instrument::renderFrames before the refill check fires)
crashes the app with:
terminate called after throwing 'std::runtime_error'
what(): SRC_DATA->data_out or SRC_DATA->data_in is NULL.
Early-return {0, 0} when either buffer has zero frames so the resampler
never touches libsamplerate with empty input. Fixes the crash without
requiring every caller to pre-check.
Member
|
@sakertooth might be interested in this |
sakertooth
reviewed
May 2, 2026
| } | ||
|
|
||
| // libsamplerate throws on empty buffers; bail before touching it. | ||
| if (input.frames() == 0 || output.frames() == 0) { return {0, 0}; } |
Contributor
There was a problem hiding this comment.
I would use the empty member function provided within the buffer views. Using these is more robust than just the frame count check because it checks if the data pointer is nullptr as well as if the channel and frame count are 0.
Suggested change
| if (input.frames() == 0 || output.frames() == 0) { return {0, 0}; } | |
| if (input.empty() || output.empty()) { return {0, 0}; } |
Contributor
There was a problem hiding this comment.
Also, this check should come before the mismatching channel count one right above it: we dont want to throw an exception when the input channel count is 0 and the output channel count is 2 for example.
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
AudioResampler::process()aborts the application when handed an empty buffer view. libsamplerate'ssrc_process()throws whenSRC_DATA->data_inordata_outis null, and an emptystd::spanyieldsdata() == nullptr.Crash report
Reproduced during long playback with an SF2 instrument track on LMMS 1.3.0-alpha (commit
ab0ed11):The resampler's sample-rate conversion path (used when the plugin's internal rate differs from the engine's output rate) can present a zero-frame slice of
Sf2Instrument::m_bufferViewtoprocess()between refill checks. libsamplerate then aborts.Root cause
AudioResampler::process()populatesSRC_DATAfromInterleavedBufferView::data()without checking whether the view has any frames. An empty span has no underlying storage, sodata() == nullptr. libsamplerate's documented behavior on null pointers isSRC_ERR_BAD_DATA, whichprocess()rethrows asstd::runtime_error.Fix
Early-return
{0, 0}when either buffer has zero frames. The zero/zero pair is already the documented "no progress" signal existing callers handle — e.g.Sf2Instrument::renderFramesbreaks the inner loop when bothinputFramesUsedandoutputFramesGeneratedare zero.Test plan
SRC_DATA NULL.fluid_synth_write_floatpath and never callAudioResampler::process()— unaffected.