Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4997451ybb; Tue, 24 Mar 2020 09:05:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuE/4pPbbv33VTgVIoazVJtwPjRi6FI3AmmAkeNQVgncP6IXkW+UM8ePTdos6fNKpN26Uwf X-Received: by 2002:a9d:3a62:: with SMTP id j89mr21214172otc.45.1585065901871; Tue, 24 Mar 2020 09:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585065901; cv=none; d=google.com; s=arc-20160816; b=E3C3L+7s09rhQgg0T39pS5jgFFTtHStXWtMfKNflj8Dw2opDPdEZmCOLBgS6PgjVIt tsojA/gxNnhizqoO+wMXDphZ2Xx7zRdwPdpvaFnzN1JY9KL5wFwVBNdPpF4Qt07hoKi3 Rs7NvQvAQcyQo/TPoRI7wndawWFtxDe7oQTpAowWMxXqUoMwG1R73Jmh4ybfGUjZycHa lfe0h9dGl/jt/CHktJJ+mXR5S9PxjWzPDFKaEGvUi6bdx/J2m3haGZZU9GsKeAhnokyB jD2qVjhBaLvmueYe4Un+SabpK+fwAo0XFXfj66Uiqms1n8wvL2eOU8acNfjCJ6q15kge ywkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=WqM8P1dLdqZvTFtrzazBWk7sovMc89YHmU7m+FIdttI=; b=edfRSgz5Mox6fuMfTPozpNCUkW0JTCDVbi8PrS58Ty5ycOCY/NKPC+Zs4T9sAgtZbc fm7JUV+OXX5qVAAivFJ8N2Jv5p2PvDCqrIlMG/63R2Mq1UYG0+h4ARcfcGw0e5L/2giM YTRz3tFd+HRIIRzcHziwTtu8JuCEyUihRf58ZZOP0BlujlQS7OZeM4D7nrUReN/HqXB+ cV3/5hhBp82+KcSXejXxgoz/UREEMaEX7O56KTxRQlr9/jj/pkHNKDCohxSMu4zSmNhl pbOtrNDlu+HRUL0GYYCPjzzE8nA+6vlg4l59+rUG11f+yBF2aWdLwgLhRJLAHAmk7j8G hFcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z65si9339955otb.197.2020.03.24.09.04.41; Tue, 24 Mar 2020 09:05:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727857AbgCXQDc (ORCPT + 99 others); Tue, 24 Mar 2020 12:03:32 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51522 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727443AbgCXQDb (ORCPT ); Tue, 24 Mar 2020 12:03:31 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: aratiu) with ESMTPSA id 8E96828C5A3 From: Adrian Ratiu To: Philipp Zabel Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ezequiel Garcia , kernel@collabora.com, kernel@pengutronix.de Subject: [PATCH v2] media: coda: jpeg: support optimized huffman tables Date: Tue, 24 Mar 2020 18:04:29 +0200 Message-Id: <20200324160429.2626-1-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Each jpeg can have the huffman tables optimized for its specific content meaning that the table lenghts and values don't match the standard table of substitutions so there's no reason to hardcode and expect the standard lengths, otherwise we just end up rejecting optimized jpegs altogether. Tested on CODA960. Signed-off-by: Adrian Ratiu --- Changes since v1: - Added test for DC tables upper boundary (Philipp) --- drivers/media/platform/coda/coda-jpeg.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c index 6a11b64efb6b..60d6e1073334 100644 --- a/drivers/media/platform/coda/coda-jpeg.c +++ b/drivers/media/platform/coda/coda-jpeg.c @@ -343,7 +343,10 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb) v4l2_err(&dev->v4l2_dev, "missing Huffman table\n"); return -EINVAL; } - if (huffman_tables[i].length != ((i & 2) ? 178 : 28)) { + /* AC tables should be between 17 -> 178, DC between 17 -> 28 */ + if (huffman_tables[i].length < 17 || + huffman_tables[i].length > 178 || + ((i & 2) == 0 && huffman_tables[i].length > 28)) { v4l2_err(&dev->v4l2_dev, "invalid Huffman table %d length: %zu\n", i, huffman_tables[i].length); @@ -357,10 +360,12 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb) return -ENOMEM; ctx->params.jpeg_huff_tab = huff_tab; } - memcpy(huff_tab->luma_dc, huffman_tables[0].start, 16 + 12); - memcpy(huff_tab->chroma_dc, huffman_tables[1].start, 16 + 12); - memcpy(huff_tab->luma_ac, huffman_tables[2].start, 16 + 162); - memcpy(huff_tab->chroma_ac, huffman_tables[3].start, 16 + 162); + + memset(huff_tab, 0, sizeof(*huff_tab)); + memcpy(huff_tab->luma_dc, huffman_tables[0].start, huffman_tables[0].length); + memcpy(huff_tab->chroma_dc, huffman_tables[1].start, huffman_tables[1].length); + memcpy(huff_tab->luma_ac, huffman_tables[2].start, huffman_tables[2].length); + memcpy(huff_tab->chroma_ac, huffman_tables[3].start, huffman_tables[3].length); /* check scan header */ for (i = 0; i < scan_header.num_components; i++) { -- 2.26.0