PR #26226 opened by Pu Cheng (GeekQAQ) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26226 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26226.patch
swr_drop_output() calls swr_convert() with a zero sample count and an uninitialized tmp_arg[] array as input. fill_audiodata() still computes in_arg[0] + i * bps (packed) or copies in_arg[i] (planar) for every channel, which is undefined for indeterminate pointers; UBSan reports "applying non-zero offset 1 to null pointer" when the stack happens to hold 0. Point all entries to a static zeroed buffer. Signed-off-by: Pu Cheng <[email protected]> >From a1c163d8bb5f4bebf4045f18bba4c78811dc7082 Mon Sep 17 00:00:00 2001 From: Pu Cheng <[email protected]> Date: Fri, 20 Nov 2026 14:34:00 +0800 Subject: [PATCH 1/2] swresample: check for an initialized context in swr_inject_silence() swr_inject_silence() calls swri_realloc_audio() on s->silence, whose bps and ch_count are only set by swr_init(). On a context that was allocated but not initialized, or after swr_close(), both are 0, and the size check in swri_realloc_audio() divides by zero (UBSan; SIGFPE on x86). swr_convert() returns an error for such a context. Return AVERROR(EINVAL) instead. Signed-off-by: Pu Cheng <[email protected]> --- libswresample/swresample.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 52ad73836e8..0cd40406c0c 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -881,6 +881,9 @@ int swr_inject_silence(struct SwrContext *s, int count){ if(count <= 0) return 0; + if (!swr_is_initialized(s)) + return AVERROR(EINVAL); + #define MAX_SILENCE_STEP 16384 while (count > MAX_SILENCE_STEP) { if ((ret = swr_inject_silence(s, MAX_SILENCE_STEP)) < 0) -- 2.54.1 >From c9f944c569ebc4f5a05adc90455b6760ca930905 Mon Sep 17 00:00:00 2001 From: Pu Cheng <[email protected]> Date: Fri, 20 Nov 2026 14:34:00 +0800 Subject: [PATCH 2/2] swresample: do not pass uninitialized pointers in swr_drop_output() swr_drop_output() calls swr_convert() with a zero sample count and an uninitialized tmp_arg[] array as input. fill_audiodata() still computes in_arg[0] + i * bps (packed) or copies in_arg[i] (planar) for every channel, which is undefined for indeterminate pointers; UBSan reports "applying non-zero offset 1 to null pointer" when the stack happens to hold 0. Point all entries to a static zeroed buffer. Signed-off-by: Pu Cheng <[email protected]> --- libswresample/swresample.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 0cd40406c0c..f93142149b9 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -864,7 +864,10 @@ int attribute_align_arg swr_convert(struct SwrContext *s, } int swr_drop_output(struct SwrContext *s, int count){ + static const uint8_t empty[SWR_CH_MAX * 8]; const uint8_t *tmp_arg[SWR_CH_MAX]; + for (int i = 0; i < SWR_CH_MAX; i++) + tmp_arg[i] = empty; s->drop_output += count; if(s->drop_output <= 0) -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
