Skip to content

Commit

Permalink
lavc/jpegtables: Handle multiple mappings to the same value
Browse files Browse the repository at this point in the history
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.

In all known files, the 2 codes are mapped to symbol 0 so only
that case is checked.

---

[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@gmail.com>
  • Loading branch information
VelocityRa committed Aug 20, 2019
1 parent 8bd18cc commit 493723a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions libavcodec/jpegtables.c
Expand Up @@ -130,14 +130,25 @@ void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
{
int i, j, k,nb, code, sym;

code = 0;
/* Some badly encoded files [1] map 2 different codes to symbol 0.
Only the first one is valid, so we zero-initialize this here and
make sure we only set it once (the first time) in the loop below.
[1]: Embedded JPEGs in "X7 RAW" and "X7 CinemaDNG" samples here:
https://www.dji.com/gr/zenmuse-x7/info#downloads
*/
huff_size[0] = 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 (sym != 0 || huff_size[sym] == 0) { /* see comment above */
huff_size[sym] = i;
huff_code[sym] = code;
}
code++;
}
code <<= 1;
Expand Down

0 comments on commit 493723a

Please sign in to comment.