PR #20355 opened by Leo Izen (Traneptora)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20355
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20355.patch

libjxl consumes no input if it returns an error, so this loops over
and over while it spits out the same error many times. If we got an
error from libjxl and consumed no input, then we instead consume the
whole packet.

Signed-off-by: Leo Izen <leo.i...@gmail.com>


>From d808b0fc63506f224182872a78e6d2646e4e177d Mon Sep 17 00:00:00 2001
From: Leo Izen <leo.i...@gmail.com>
Date: Wed, 27 Aug 2025 11:53:23 -0400
Subject: [PATCH] avcodec/libjxldec: consume input on error

libjxl consumes no input if it returns an error, so this loops over
and over while it spits out the same error many times. If we got an
error from libjxl and consumed no input, then we instead consume the
whole packet.

Signed-off-by: Leo Izen <leo.i...@gmail.com>
---
 libavcodec/libjxldec.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index 8ce69015bf..6e42b3bb2c 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -414,12 +414,22 @@ static int libjxl_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
          * the number of bytes that it did read
          */
         remaining = JxlDecoderReleaseInput(ctx->decoder);
-        pkt->data += pkt->size - remaining;
+        size_t consumed = pkt->size - remaining;
+        pkt->data += consumed;
         pkt->size = remaining;
 
         switch(jret) {
         case JXL_DEC_ERROR:
             av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
+            if (!consumed) {
+                /*
+                 * we consume all remaining input on error, if nothing was 
consumed
+                 * this prevents libjxl from consuming nothing forever
+                 * and just dumping the last error over and over
+                 */
+                pkt->data += pkt->size;
+                pkt->size = 0;
+            }
             return AVERROR_INVALIDDATA;
         case JXL_DEC_NEED_MORE_INPUT:
             av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-le...@ffmpeg.org

Reply via email to