[FFmpeg-devel] [PATCH v12 05/14] lavc/jpegtables: Handle multiple mappings to the same value

Nick Renieris velocityra at gmail.com
Sat Aug 10 16:42:38 EEST 2019


I haven't seen any files with sym!=0, just thought I'd solve the general case.
I'll change only for sym==0. Can always be changed later if any such
samples are found.


Στις Σάβ, 10 Αυγ 2019 στις 4:11 μ.μ., ο/η Michael Niedermayer
<michael at niedermayer.cc> έγραψε:
>
> On Fri, Aug 09, 2019 at 07:29:50PM +0300, Nick Renieris wrote:
> > From: Nick Renieris <velocityra at gmail.com>
> >
> > Some JPEGs [1] have incorrect DHT entries that map 2 codes to
> > the same value.
> >
> > The second (last) mapping does not ever actually appear in the
> > code stream, therefore ignoring any mappings after the first one
> > fixes this.
> >
> > Without this, an "mjpeg_decode_dc: bad vlc: 0:0" error is thrown.
> >
> > ---
> >
> > [1]: Embedded JPEGs in "X7 RAW" and "X7 CinemaDNG" samples here:
> >      https://www.dji.com/gr/zenmuse-x7/info#downloads
> >
> > Signed-off-by: Nick Renieris <velocityra at gmail.com>
> > ---
> >  libavcodec/jpegtables.c | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/jpegtables.c b/libavcodec/jpegtables.c
> > index cbe5523cb4..6f596cfc92 100644
> > --- a/libavcodec/jpegtables.c
> > +++ b/libavcodec/jpegtables.c
> > @@ -130,14 +130,27 @@ void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
> >  {
> >      int i, j, k,nb, code, sym;
> >
> > -    code = 0;
> > +    /* Zero-initialize huff_size (needed for multiple mappings check below) */
> > +    k = 0;
> > +    for(i=1;i<=16;i++) {
> > +        nb = bits_table[i];
> > +        for(j=0;j<nb;j++) {
> > +            sym = val_table[k++];
> > +            huff_size[sym] = 0;
> > +        }
> > +    }
> > +
> >      k = 0;
> > +    code = 0;
> >      for(i=1;i<=16;i++) {
> >          nb = bits_table[i];
> >          for(j=0;j<nb;j++) {
> >              sym = val_table[k++];
> > -            huff_size[sym] = i;
> > -            huff_code[sym] = code;
> > +            /* If there are multiple mappings to the same sym (bad files), keep the first code */
> > +            if (huff_size[sym] == 0) {
> > +                huff_size[sym] = i;
> > +                huff_code[sym] = code;
> > +            }
>
> do these occur with sym different from 0 ?
> if its just 0 then this can be simplified alot
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I do not agree with what you have to say, but I'll defend to the death your
> right to say it. -- Voltaire
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list