From: Ramiro Polla via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: Ramiro Polla <code@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH] avcodec/mjpegdec: ignore APPx stubs unless AV_EF_EXPLODE is set (PR #20422) Message-ID: <175694334437.25.1202515690322753656@463a07221176> (raw) PR #20422 opened by Ramiro Polla (ramiro) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20422 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20422.patch >From 073afa4be351bf99897033e5299cb680109727a1 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <ramiro.polla@gmail.com> Date: Thu, 17 Oct 2024 13:00:11 +0200 Subject: [PATCH 1/2] avcodec/mjpegdec: fix skipping of bytes for unknown APPx markers The loop to skip the remaining bytes was off by one for all markers except for Adob. This patch uses post-decrement instead of pre-decrement in the while loop to make the len value easier to understand, and updates the len value to reflect this change for the Adob marker. --- libavcodec/mjpegdec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 4d6379805c..c44d7f8181 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -1934,7 +1934,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) } if ( id == AV_RB32("Adob") - && len >= 7 + && len >= 8 && show_bits(&s->gb, 8) == 'e' && show_bits_long(&s->gb, 32) != AV_RB32("e_CM")) { skip_bits(&s->gb, 8); /* 'e' */ @@ -1944,7 +1944,7 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) s->adobe_transform = get_bits(&s->gb, 8); if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found, transform=%d\n", s->adobe_transform); - len -= 7; + len -= 8; goto out; } @@ -2153,7 +2153,7 @@ out: if (len < 0) av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n"); - while (--len > 0) + while (len-- > 0) skip_bits(&s->gb, 8); return 0; -- 2.49.1 >From 1bee4a6ec5ad5cdfd15ccf09fe7d45d59b00a060 Mon Sep 17 00:00:00 2001 From: Ramiro Polla <ramiro.polla@gmail.com> Date: Tue, 1 Oct 2024 20:50:05 +0200 Subject: [PATCH 2/2] avcodec/mjpegdec: ignore APPx stubs unless AV_EF_EXPLODE is set Consider APPx fields that are too short to contain an id field (32-bit) as stubs, and ignore them if AV_EF_EXPLODE is not set. This has been seen in the MJPEG output from some webcams (such as the Logitech C270 and C920) and the JPEG images embedded in DNG images from the Pentax K-1 camera. --- libavcodec/mjpegdec.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index c44d7f8181..3dde759fea 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -1859,20 +1859,22 @@ static int mjpeg_decode_app(MJpegDecodeContext *s) int len, id, i; len = get_bits(&s->gb, 16); - if (len < 6) { - if (s->bayer) { - // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain unknown APP0 markers - av_log(s->avctx, AV_LOG_WARNING, "skipping APPx (len=%"PRId32") for bayer-encoded image\n", len); - skip_bits(&s->gb, len); - return 0; - } else + if (len < 2) + return AVERROR_INVALIDDATA; + len -= 2; + + if (len < 4) { + if (s->avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; + av_log(s->avctx, AV_LOG_VERBOSE, "skipping APPx stub (len=%" PRId32 ")\n", len); + goto out; } + if (8 * len > get_bits_left(&s->gb)) return AVERROR_INVALIDDATA; id = get_bits_long(&s->gb, 32); - len -= 6; + len -= 4; if (s->avctx->debug & FF_DEBUG_STARTCODE) av_log(s->avctx, AV_LOG_DEBUG, "APPx (%s / %8X) len=%d\n", -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-09-03 23:49 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=175694334437.25.1202515690322753656@463a07221176 \ --to=ffmpeg-devel@ffmpeg.org \ --cc=code@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git