Commit 51fc17901a for ffmpeg

commit 51fc17901a3b0252f1cbe02c84bacf91b7ab412a
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Wed Nov 11 05:09:41 2026 +0100

    avcodec/mjpegdec: reject lossless RCT scans that do not code all components

    Fixes: use of uninitialized memory
    Fixes: fFQc8EgXP8v9

    Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25034

    Use of uninitialized memory Replicated through UnModified FFmpeg with Valgrind

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index df46b2b8dc..caa6b9d1d9 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1120,6 +1120,8 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s)
         if (s->rct || s->pegasus_rct)
             return AVERROR_INVALIDDATA;
     }
+    if ((s->rct || s->pegasus_rct) && nb_components != s->nb_components)
+        return AVERROR_INVALIDDATA;

     av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
                    (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));