From 493723a9a18526526836baf2f0c373e9ede9100c Mon Sep 17 00:00:00 2001 From: Nick Renieris Date: Sun, 28 Jul 2019 15:22:32 +0300 Subject: [PATCH] lavc/jpegtables: Handle multiple mappings to the same value 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 --- libavcodec/jpegtables.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/jpegtables.c b/libavcodec/jpegtables.c index cbe5523cb43df..fa5c6f9fc58bb 100644 --- a/libavcodec/jpegtables.c +++ b/libavcodec/jpegtables.c @@ -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