PR #25793 opened by Forgejo_Fairy URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25793 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25793.patch
Fixes #24188. Use `av_realloc_array()` for the per-thread coefficient scratch buffer and commit its pointer, thread count, and size only after allocation succeeds. A failed resize now retains the previous valid allocation and extents so the next HQ picture can retry. Verification on arm64: the attached interposer made the unmodified CLI exit with SIGSEGV (139) after a selected scratch allocation failure; the patched CLI logged the allocation error, retried, and completed without crashing. An unfaulted HQ decode, `fate-dirac`, and `fate-dirac-low-delay` passed. >From 4e2d8572b425dfc293dcff65a2e4b22a5d215f09 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer <[email protected]> Date: Thu, 5 Nov 2026 23:59:22 +0000 Subject: [PATCH] avcodec/diracdec: retain HQ scratch buffer on allocation failure Keep the existing scratch buffer and its published extents if resizing fails. Use av_realloc_array(), which leaves the old allocation intact, and commit the pointer and extents only after success. This allows decoding to retry the allocation on a later picture without using a null scratch buffer. Fixes: #24188 Assisted-by: Fairy --- libavcodec/diracdec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c index aa54dbaff2e..719eeaaaf9f 100644 --- a/libavcodec/diracdec.c +++ b/libavcodec/diracdec.c @@ -958,13 +958,15 @@ static int decode_lowdelay(DiracContext *s) if (s->threads_num_buf != avctx->thread_count || s->thread_buf_size != coef_buf_size) { - s->threads_num_buf = avctx->thread_count; - s->thread_buf_size = coef_buf_size; - s->thread_buf = av_realloc_f(s->thread_buf, avctx->thread_count, s->thread_buf_size); - if (!s->thread_buf) { + uint8_t *thread_buf = av_realloc_array(s->thread_buf, avctx->thread_count, + coef_buf_size); + if (!thread_buf) { av_log(s->avctx, AV_LOG_ERROR, "thread buffer allocation failure\n"); return AVERROR(ENOMEM); } + s->thread_buf = thread_buf; + s->threads_num_buf = avctx->thread_count; + s->thread_buf_size = coef_buf_size; } align_get_bits(&s->gb); -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
