From patchwork Thu Aug 29 13:10:44 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: 14784 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 82D1544A068 for ; Thu, 29 Aug 2019 16:12:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 656EF687F31; Thu, 29 Aug 2019 16:12:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ABEEF687F1C for ; Thu, 29 Aug 2019 16:12:17 +0300 (EEST) Received: by mail-wr1-f43.google.com with SMTP id y19so3395186wrd.3 for ; Thu, 29 Aug 2019 06:12:17 -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=xKAoZiZWiJp58Ie9ixW/AdhOS3wPDo93o35OjIiNHTU=; b=Poum3zYlm9WdWnWYHrVzUakIzUmoUxZ2DRccpuD87kSOfvIcEb79Kx1geQR+Drqg+J FwDis1w6tTXD+IeSvDcuyNZIiuFm4XOb1Jto+3Zr60Jxck3tyDJ12D/Xy77BZ1bb/cdP awEIRo6wAnMf0LDNneoB+BR8Pwia5MDVTJABpasjXdROi8/MZ9Wv/LlREc0jy+jCGhLx 6OdcchU7Cmn8Jui6idEri5/d5qvnryXXwNZx98BAD7hVa01udtMOC0yPNkgibIl1duGK iBKXdOEzHzd0U4cqIcYKx49NNpS2RdEY+xchd7TW3Ook7erzn74dALOD4aM3JCt+7kTh wVPw== 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=xKAoZiZWiJp58Ie9ixW/AdhOS3wPDo93o35OjIiNHTU=; b=MzkbdsGFZIsTSOdw2zPMp/jlcA1jJC8Qp50n/MNTDomAyeKy53lBrvJC2Vn1FjV5Hh ekt2QKtexsVgIwVVgU0nbw4aGA/byLz7JiB8+b7Eq6NEfV+N8/a7O/fOjbkt4RVhQvjP ZT2H6nPGJlKL+QTO+6esSmhZv59YLi6V9DRNbQeE4lFEGEb/kZey7qw3NoBsRY9gFTTZ Os5Jd5FudPc0Tx4ulPvtc0/FiQCHZHtTFvI7+m+MpodG0t1zY8p9zEGvXZH89n6fFpgb ZVZsj+50JObkkmrjIbwq8+cr9+O/fjMg+FyAYafPPYcUVIVb4j3IcBJCtQEXkROCnHsn zFug== X-Gm-Message-State: APjAAAVEnQa3oIl5a6s8mCimC0R/PLI+5fNHuYm0KXBGBG2f0wgQR8Gg kc0COBZAs6PRFzke/YUUtEm2UUCj X-Google-Smtp-Source: APXvYqxh7SGDnTi9paoYpGJxpQJDb2fiyYQG4myKrJxwDjbh9uCY4C+EKWTXsKGufITMi+QDsv5wLQ== X-Received: by 2002:adf:e30e:: with SMTP id b14mr11519361wrj.168.1567084336905; Thu, 29 Aug 2019 06:12:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:240d:9b00:4ca1:2ce9:2e6c:c246]) by smtp.gmail.com with ESMTPSA id m17sm1676644wrs.9.2019.08.29.06.12.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 06:12:16 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Aug 2019 16:10:44 +0300 Message-Id: <20190829131054.16404-5-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190829131054.16404-1-velocityra@gmail.com> References: <20190829131054.16404-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v17 05/15] 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