[FFmpeg-devel] [PATCH 2/2] avcodec/mjpegdec: silently ignore APPx stubs

Michael Niedermayer michael at niedermayer.cc
Mon Oct 21 02:40:59 EEST 2024


On Thu, Oct 17, 2024 at 01:00:12PM +0200, Ramiro Polla wrote:
> Consider APPx fields that are too short to contain an id field (32-bit)
> as stubs, and silently ignore them.
> 
> 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 | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index a775fdca30..3cd9904595 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -1856,20 +1856,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
> -            return AVERROR_INVALIDDATA;
> +    if (len < 2)
> +        return AVERROR_INVALIDDATA;
> +    len -= 2;
> +
> +    if (len < 4) {
> +        /* Silently ignore APPx stubs */
> +        if (show_bits(&s->gb, 8 * len) == 0)
> +            goto out;
> +        return AVERROR_INVALIDDATA;

this silently errors on the ones it doesnt ignore, it was more informative
before

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Some people wanted to paint the bikeshed green, some blue and some pink.
People argued and fought, when they finally agreed, only rust was left.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241021/e74fc1e3/attachment.sig>


More information about the ffmpeg-devel mailing list