[FFmpeg-devel,v12,12/14] lavc/mjpegdec: Skip useless APPx marker on bayer images

Submitted by velocityra@gmail.com on Aug. 9, 2019, 4:29 p.m.

Details

Message ID 20190809162959.17924-12-velocityra@gmail.com
State New
Headers show

Commit Message

velocityra@gmail.com Aug. 9, 2019, 4:29 p.m.
From: Nick Renieris <velocityra@gmail.com>

Samples:
- Embedded JPEG images in the DNG images here:
  https://www.photographyblog.com/previews/pentax_k1_photos

Signed-off-by: Nick Renieris <velocityra@gmail.com>
---
 libavcodec/mjpegdec.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Aug. 10, 2019, 12:15 p.m.
On Fri, Aug 09, 2019 at 07:29:57PM +0300, Nick Renieris wrote:
> From: Nick Renieris <velocityra@gmail.com>
> 
> Samples:
> - Embedded JPEG images in the DNG images here:
>   https://www.photographyblog.com/previews/pentax_k1_photos
> 
> Signed-off-by: Nick Renieris <velocityra@gmail.com>
> ---
>  libavcodec/mjpegdec.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index 0a920a7144..e7b273a363 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -1807,8 +1807,15 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
>      int len, id, i;
>  
>      len = get_bits(&s->gb, 16);
> -    if (len < 6)
> -        return AVERROR_INVALIDDATA;
> +    if (len < 6) {
> +        if (s->bayer) {
> +            // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain useless APP0 markers

"useless" is a quite generic term, is it known what the contain why they
are there ?

thx

[...]
velocityra@gmail.com Aug. 10, 2019, 1:52 p.m.
The data the marker contains is only 2 bytes and they're 0x0000 in the
samples above. I don't know what they're for.


Στις Σάβ, 10 Αυγ 2019 στις 3:16 μ.μ., ο/η Michael Niedermayer
<michael@niedermayer.cc> έγραψε:
>
> On Fri, Aug 09, 2019 at 07:29:57PM +0300, Nick Renieris wrote:
> > From: Nick Renieris <velocityra@gmail.com>
> >
> > Samples:
> > - Embedded JPEG images in the DNG images here:
> >   https://www.photographyblog.com/previews/pentax_k1_photos
> >
> > Signed-off-by: Nick Renieris <velocityra@gmail.com>
> > ---
> >  libavcodec/mjpegdec.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> > index 0a920a7144..e7b273a363 100644
> > --- a/libavcodec/mjpegdec.c
> > +++ b/libavcodec/mjpegdec.c
> > @@ -1807,8 +1807,15 @@ static int mjpeg_decode_app(MJpegDecodeContext *s)
> >      int len, id, i;
> >
> >      len = get_bits(&s->gb, 16);
> > -    if (len < 6)
> > -        return AVERROR_INVALIDDATA;
> > +    if (len < 6) {
> > +        if (s->bayer) {
> > +            // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain useless APP0 markers
>
> "useless" is a quite generic term, is it known what the contain why they
> are there ?
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Asymptotically faster algorithms should always be preferred if you have
> asymptotical amounts of data
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Aug. 10, 2019, 9:13 p.m.
On Sat, Aug 10, 2019 at 04:52:10PM +0300, Nick Renieris wrote:
> The data the marker contains is only 2 bytes and they're 0x0000 in the
> samples above. I don't know what they're for.

ok then please call them unknown and not useless in the comments

thanks

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 0a920a7144..e7b273a363 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -1807,8 +1807,15 @@  static int mjpeg_decode_app(MJpegDecodeContext *s)
     int len, id, i;
 
     len = get_bits(&s->gb, 16);
-    if (len < 6)
-        return AVERROR_INVALIDDATA;
+    if (len < 6) {
+        if (s->bayer) {
+            // Pentax K-1 (digital camera) JPEG images embedded in DNG images contain useless 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 (8 * len > get_bits_left(&s->gb))
         return AVERROR_INVALIDDATA;