Fix for Crash when Audio Resampling Fails #13751
Replies: 2 comments
|
Please do not submit bug reports to the discussions. If this is intended to be a PR for a bug fix, please submit it as such. The formatting is broken here and it makes it impossible to read as a patch. If this is supposed to be a bug report, please use issues and our issue report template. |
0 replies
|
I would have used to proper upload method, but some silly person decided
that I had to upload the entire log file along with the actual patch fixing
it in order to do so. Hence why I was forced to put it here.
…On Tue, Aug 4, 2026, 00:30 Joel Bethke ***@***.***> wrote:
Please do not submit bug reports to the discussions. If this is intended
to be a PR for a bug fix, please submit it as such. The formatting is
broken here and it makes it impossible to read as a patch.
If this is supposed to be a bug report, please use issues and our issue
report template.
—
Reply to this email directly, view it on GitHub
<#13751?email_source=notifications&email_token=ATOTXI325MJVAPWCNWIVWC35IFYJFA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYHA4TEMRZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVRTG633UMVZF6Y3MNFRWW#discussioncomment-17889229>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATOTXI3CYZPMTUTRCKDE6235IFYJFAVCNFSNUABHKJSXA33TNF2G64TZHMYTGMRTGMYTKOB3IRUXGY3VONZWS33OHMYTANJUHA3DCM5BOYBA>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/ATOTXI2EGU6RDY4MVJDFFNL5IFYJFA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYHA4TEMRZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVJTG633UMVZF62LPOM>
and Android
<https://github.com/notifications/mobile/android/ATOTXIYSZXKUA66WMH46LID5IFYJFA5CNFSNUABIM5UWIORPF5TWS5BNNB2WEL2ENFZWG5LTONUW63SDN5WW2ZLOOQXTCNZYHA4TEMRZUZZGKYLTN5XKMYLVORUG64VFMV3GK3TUVZTG633UMVZF6YLOMRZG62LE>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Somebody sent me two crash dumps off the same machine 28 minutes apart. Both come out of a WASAPI capture callback. One crashes inside swresample, the other one in copy_audio_data's memcpy. Turns out it's the same bug with two ways out.
audio_resampler_resample never looks at what av_samples_alloc gives back, and it sets output_size either way. So when the alloc fails, swr_convert gets null planes and a size telling it those planes are good. That's the first dump.
Two more problems in the same spot. av_freep only clears plane 0, and on a planar buffer the rest of the planes point into that same block, so they're left dangling once it's freed. The frame estimate also gets truncated to int, and that wraps to negative if a device hands back an incorrect frame count or leaves a large delay sitting in the queue.
The second dump is the caller. process_audio throws the return value away, so the "swr_convert failed" path that already exists just falls straight through into copy_audio_data with null planes. It logs the error and then crashes on the next line.
Fixing either one by itself just moves the crash over to the other one, which is what those two dumps are showing.
Also we should put the source name and the conversion into the resampler creation failure message. Otherwise it mutes the source and tells the user nothing about why.
diff --git a/libobs/media-io/audio-resampler-ffmpeg.c b/libobs/media-io/audio-resampler-ffmpeg.c
index eb5be4f74..2f2167218 100644
--- a/libobs/media-io/audio-resampler-ffmpeg.c
+++ b/libobs/media-io/audio-resampler-ffmpeg.c
@@ -15,6 +15,9 @@
along with this program. If not, see http://www.gnu.org/licenses/.
******************************************************************************/
+#include <inttypes.h>
+#include <limits.h>
+
#include "../util/bmem.h"
#include "audio-resampler.h"
#include "audio-io.h"
@@ -188,8 +191,16 @@ bool audio_resampler_resample(audio_resampler_t *rs, uint8_t *output[], uint32_t
int ret;
int64_t estimated = av_rescale_rnd(delay + (int64_t)in_frames, (int64_t)rs->output_freq,
/* a device glitching its format can leave a large delay queued or
if (estimated < 0 || estimated > INT_MAX) {
}
*ts_offset = (uint64_t)swr_get_delay(context, 1000000000);
@@ -198,9 +209,19 @@ bool audio_resampler_resample(audio_resampler_t *rs, uint8_t *output[], uint32_t
if (rs->output_buffer[0])
av_freep(&rs->output_buffer[0]);
}
ret = swr_convert(context, rs->output_buffer, rs->output_size, (const uint8_t **)input, in_frames);
diff --git a/libobs/obs-source.c b/libobs/obs-source.c
index f025f6a13..f0737756e 100644
--- a/libobs/obs-source.c
+++ b/libobs/obs-source.c
@@ -3977,7 +3977,12 @@ static inline void reset_resampler(obs_source_t *source, const struct obs_source
source->audio_failed = source->resampler == NULL;
if (source->resampler == NULL)
}
static void copy_audio_data(obs_source_t *source, const uint8_t *const data[], uint32_t frames, uint64_t ts)
@@ -4093,8 +4098,11 @@ static void process_audio(obs_source_t *source, const struct obs_source_audio *a
All reactions