Repository navigation
Conversation
typed_resample() swaps in a newly allocated sample buffer through Buffer::set_buf_data(), which didn't update size_. After squashing a buffer (e.g. when a source's rate is overridden, so its audio is resampled to fit) size() still reported the old, larger size, so: - ~Buffer handed the smaller block to the recycler under the larger size, and the next allocation of that size wrote past its end; - allocate(), resize(), extend_size() and extend() sized from it. This corrupted the heap during playback, showing up later as crashes in the audio cache and in malloc. set_buf_data() now takes the size of the new buffer. typed_resample() also handles a zero-length result, which looped ~2^32 times writing past the buffer, and an empty input, which was read before its start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Sam.Richards@taurich.org <Sam.Richards@taurich.org>
richardssam
force-pushed
the
fix/audio-buffer-recycling
branch
from
November 18, 2026 14:47
a7b19ee to
46dc958
Compare
tedwaine
merged commit Nov 20, 2026
e7c1e40
into
AcademySoftwareFoundation:develop
3 of 4 checks passed
Collaborator
|
A nasty bug. thanks. |
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.
Summarize your change.
When a source's audio is stretched or squashed to fit its frame rate,
typed_resample()gives theAudioBuffernew, differently sized memory throughBuffer::set_buf_data(). That call didn't updatesize_, so the buffer still reported its old size afterwards. As a result:allocate(),resize(),extend_size()andextend()also sized themselves from the stale value.set_buf_data()now takes the size of the new buffer.typed_resample()also now handles two edge cases it got wrong before: a zero-length result, and an empty input.Describe the reason for the change.
The stale size corrupted the heap during normal playback whenever audio was resampled. The crashes came later and somewhere else: freeing entries in
GlobalAudioCacheActor, or malloc aborting with "memory corruption of free block". Running under macOS Guard Malloc caught the bad write, which led totyped_resample().Describe what you have tested and on which operating system.
macOS 26.6 on an M2 Max.
AudioBuffer.ResampleUpdatesSizecheckssize()after squashing, after stretching, and afterextend().AudioBuffer.ResampleEmptycovers a zero-length result and an empty input.typed_resample()while freeing a buffer that had been written past. After the fix it played without any Guard Malloc errors.Add a list of changes, and note any that might need special attention during the review.
include/xstudio/media_reader/buffer.hpp:set_buf_data()now takes the size of the new buffer and updatessize_.typed_resample()is the only caller in the repo.src/media_reader/src/media_reader.cpp:typed_resample()passes the new size.int n = out_samples - 1; while (n--)ran about 2^32 times, writing past the buffer.src/media_reader/test/media_reader_test.cpp: the two newAudioBuffertests.If possible, provide screenshots.
N/A
Developed with assistance from Claude.