Commit 3aa561b0dd for ffmpeg
commit 3aa561b0dd2054182fbb9548b4526e8500d52a52
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Sat Oct 24 05:47:15 2026 +0200
avcodec/libsvtjpegxsdec: check the dimensions before initializing the decoder
Since the dimensions are now updated before the decoder is
re-initialized, decoder_initialized is cleared when the old decoder is
closed, so that a failed re-initialization cannot leave the closed
decoder in use.
Fixes: memleak
Fixes: qEiTY2cyEBYu (AISLE-2026-0150-00638)
Memory and thread leak Replicated through UnModified FFmpeg
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
diff --git a/libavcodec/libsvtjpegxsdec.c b/libavcodec/libsvtjpegxsdec.c
index 7a325c4446..8a80cd560d 100644
--- a/libavcodec/libsvtjpegxsdec.c
+++ b/libavcodec/libsvtjpegxsdec.c
@@ -118,8 +118,17 @@ static int svt_jpegxs_dec_decode(AVCodecContext* avctx, AVFrame* picture, int* g
if (!svt_dec->decoder_initialized || ret != avctx->pix_fmt ||
avctx->width != svt_dec->config.width || avctx->height != svt_dec->config.height) {
+ avctx->pix_fmt = ret;
+
+ ret = ff_set_dimensions(avctx, svt_dec->config.width, svt_dec->config.height);
+ if (ret < 0) {
+ av_log(avctx, AV_LOG_ERROR, "ff_set_dimensions failed, err=%d\n", ret);
+ return ret;
+ }
+
if (svt_dec->decoder_initialized)
svt_jpeg_xs_decoder_close(&svt_dec->decoder);
+ svt_dec->decoder_initialized = 0;
err = svt_jpeg_xs_decoder_init(SVT_JPEGXS_API_VER_MAJOR, SVT_JPEGXS_API_VER_MINOR,
&svt_dec->decoder, avpkt->data, avpkt->size, &svt_dec->config);
if (err) {
@@ -127,14 +136,6 @@ static int svt_jpegxs_dec_decode(AVCodecContext* avctx, AVFrame* picture, int* g
return AVERROR_EXTERNAL;
}
- avctx->pix_fmt = ret;
-
- ret = ff_set_dimensions(avctx, svt_dec->config.width, svt_dec->config.height);
- if (ret < 0) {
- av_log(avctx, AV_LOG_ERROR, "ff_set_dimensions failed, err=%d\n", ret);
- return ret;
- }
-
svt_dec->decoder_initialized = 1;
}