Commit a0410859ec for ffmpeg
commit a0410859ec4a4361eb0835de508f7ec5e9313d2b
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Thu Nov 5 23:59:22 2026 +0000
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
diff --git a/libavcodec/diracdec.c b/libavcodec/diracdec.c
index aa54dbaff2..719eeaaaf9 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);