From patchwork Sun Aug 11 14:45:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: velocityra@gmail.com X-Patchwork-Id: 14418 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0703D448588 for ; Sun, 11 Aug 2019 17:46:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECD2A68AC64; Sun, 11 Aug 2019 17:46:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B93268AC00 for ; Sun, 11 Aug 2019 17:46:30 +0300 (EEST) Received: by mail-wr1-f49.google.com with SMTP id j16so180786wrr.8 for ; Sun, 11 Aug 2019 07:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dZqAL7T3LB4dZNgMyJvdcoYhO6qjbnyPcWsa+u0mNOI=; b=TjEfieqy44slY/3t6c1ppRpnrZH9cIaHFbm5on63XWEs2gpy2n751ivQqfu+8xEcFB hxYCptVdNGsTCuf5uCPV5UuCJC1sJ6Qs6mUmR7E8/pk4rxkMQdKTvnpUJlvzFzIBMyTO vQG8QCe8YU3WXWUVAqYll1BMpNxkdZ07dBUqWqg6MyZ/mhrbksTw5bV/fsNRHkIGn+wI 9fqLDGd55uhg+/K1tJtbYkcByppsmfSQ0dthWAvQNwCleBaCb1NGNUG4EtFYW17spK40 lKZ3xoNa+4b6aa4U0kkWiQakXjniFSQjBLaQb/BPwcZ9LD57u9eZZG8LRlwV0kVr/6jO Pwvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dZqAL7T3LB4dZNgMyJvdcoYhO6qjbnyPcWsa+u0mNOI=; b=mTxZKqhwWcF4aEcgUWdv+gezG5kB3IbFvyehEFQ3YoGznisBc5NlbKw+SHwXef0D8h BtqosRz6kHwoxgbEfC+ZrzLV2Vb/H9qMCMC8XZKw1KMA/baIhOQG5NkCxS8KFQ4hu0R5 qK5e7c4tZQnULR9zXf9O28v15s9YaGMUkOxFA/SpVSwSnMTre/kqRHfGrK48cH1KqvMU q8gejMjKpXfxFZQ3uYTf2kScXCskV/1poNuGImVnVieywEgPXi9v/Vr71l/oVKE4W2SJ dVBLXoIBiRl0S22UkzxNse7wGkwLXJgIIxpkqSXz6xzrgme6IyBQxw3OUQ9qpKz7rcCH BPiA== X-Gm-Message-State: APjAAAUsHaRkrjvDnWnGCd2EpYL5/HKw/OqED25BKR1SURB9vnkwbwqR FBA0qK95rspQMTm4RTDYU51v34X6fGo= X-Google-Smtp-Source: APXvYqy01MgBpzSxaJtW9oooITbxaP3qTtF8AeGKe0jUitcgzcR3kijqcc8ImU0adiyq7w2N7gzUNA== X-Received: by 2002:a1c:a584:: with SMTP id o126mr23023804wme.147.1565534789529; Sun, 11 Aug 2019 07:46:29 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:94bc:d60f:d153:ccb1]) by smtp.gmail.com with ESMTPSA id f10sm8376360wrm.31.2019.08.11.07.46.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Aug 2019 07:46:29 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Aug 2019 17:45:33 +0300 Message-Id: <20190811144542.11704-5-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190811144542.11704-1-velocityra@gmail.com> References: <20190811073641.GZ3219@michaelspb> <20190811144542.11704-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v14 05/14] lavc/jpegtables: Handle multiple mappings to the same value X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nick Renieris Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Nick Renieris 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 cbe5523cb4..fa5c6f9fc5 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