This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch release/8.1
in repository ffmpeg.

commit 959b0d15633e8e8b88e94aafb13c9acef3bded36
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Thu Jun 4 01:47:14 2026 +0200
Commit:     Michael Niedermayer <[email protected]>
CommitDate: Sat Sep 19 16:59:28 2026 +0200

    avcodec/jpeglsdec: bound cumulative decoded JPEG-LS height per packet
    
    Fixes: Timeout
    Fixes: 
509211998/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THP_fuzzer-5098892286033920
    Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
    Signed-off-by: Michael Niedermayer <[email protected]>
    (cherry picked from commit 2ff28aca4b3931ee3f551b124851ae7c41a4cdbe)
---
 libavcodec/jpeglsdec.c | 11 +++++++++++
 libavcodec/mjpegdec.c  |  1 +
 libavcodec/mjpegdec.h  |  1 +
 3 files changed, 13 insertions(+)

diff --git a/libavcodec/jpeglsdec.c b/libavcodec/jpeglsdec.c
index 5c2f0f420d..e744021e53 100644
--- a/libavcodec/jpeglsdec.c
+++ b/libavcodec/jpeglsdec.c
@@ -363,6 +363,15 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s)
     int off = 0, stride = 1, width, shift, ret = 0;
     int decoded_height = 0;
 
+    /* Bound the total amount of JPEG-LS decoding work per packet:
+     * Per T.87, ILV=0 uses one scan per component while ILV=1/2 use a single
+     * interleaved scan, and ff_mjpeg_decode_sof() rejects subsampled JPEG-LS,
+     * so a valid image needs at most height * nb_components
+     * (<= height * MAX_COMPONENTS) rows of decoding. The extra factor of 2
+     * is slack so odd, damaged and weird files are not rejected. */
+    if (s->total_ls_decoded_height > s->height * 2LL * MAX_COMPONENTS)
+        return AVERROR_INVALIDDATA;
+
     if (!state) {
         state = av_malloc(sizeof(*state));
         if (!state)
@@ -491,6 +500,8 @@ int ff_jpegls_decode_picture(MJpegDecodeContext *s)
         goto end;
     }
 
+    s->total_ls_decoded_height += decoded_height;
+
     if (s->xfrm && s->nb_components == 3) {
         int x, w;
 
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index af27a9063f..33c31ad6aa 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2418,6 +2418,7 @@ int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, 
AVFrame *frame,
     int is16bit;
 
     s->force_pal8 = 0;
+    s->total_ls_decoded_height = 0;
 
     s->buf_size = buf_size;
 
diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h
index 3d5c87ee54..2550f45233 100644
--- a/libavcodec/mjpegdec.h
+++ b/libavcodec/mjpegdec.h
@@ -140,6 +140,7 @@ typedef struct MJpegDecodeContext {
     int mjpb_skiptosod;
 
     int cur_scan; /* current scan, used by JPEG-LS */
+    int64_t total_ls_decoded_height; /* cumulative JPEG-LS rows decoded in the 
current packet */
     int flipped; /* true if picture is flipped */
 
     uint16_t (*ljpeg_buffer)[4];

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to