Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp949227pxu; Wed, 2 Dec 2020 07:23:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOCJilr9nqCGdBiMr7zMI8PMkPKSh4zh62psFbv7WutSO0nR7OpFEuOMErm8KsPZfkPCp8 X-Received: by 2002:a17:906:f85:: with SMTP id q5mr271302ejj.105.1606922637220; Wed, 02 Dec 2020 07:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606922637; cv=none; d=google.com; s=arc-20160816; b=bdijVoa8jcKswFR5IOIIVPmcoxFLvQxXpp1vhwmDIq0TtZOoiQYFu+Dg8I6H5BNbUH RVdtOkNXMZohtIqMRgUU1J7BFn5MGNzbjPMGiA40kagxnF73YwM+QZpIcetPBcSnb42q Q+EZ6T44f+nL+I57Li8YIEq5WQarHMz2sAtisyqR1VBJGOxF8nU6iG4hm2gOnrtUlt4e T4jGeKG74cg6AFkkYmVdR0yzPj+b568ht4hgiUuq46WbuCUmmSAV/D5LA3nc+9pBY1U/ UxTPDW8z+tg3bdJu7iyVYyLZszV7Zsr7uFvyyxokcIbXBn7lotqgH8TE+f23hANR4bTM GPpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=RluaytijHQk2ANUlJxfjLfyEw2LxE5zVJS/JjlZZzu0=; b=GwhN3cXtfH+DPnvIM39H2X6qDVwwwT/dTwkYZE9Ixe2W/9D51t3f6PXnBFkJjP9918 O7TEVCFgwCw8sqvwS44FnK/Ts7fwux/GydSJ6FLCmhUhQfnaYBRtoHrZcmKa3mJdjkA1 Rq1CvKigtF0Huy9P/u4L4ZBeeT3ftHDREbcmut+94yII+Gxo6bWX88xNJlwJ4AC7N5oX cDJG8A3yrohl9Y2nRNv2dpARGFmh9LO6NzdTho0EbFofR9Ghh3fyIbfWZQSSMCWyW38r 2vE7I46aM4z45FL3hI4uu56hwkcVjpAPV3YinyCquQkGeFteFFFtEV7nwtZPJ7zHLoCT tQtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a18si128391ejf.618.2020.12.02.07.23.32; Wed, 02 Dec 2020 07:23:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387424AbgLBPTd convert rfc822-to-8bit (ORCPT + 99 others); Wed, 2 Dec 2020 10:19:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387399AbgLBPTd (ORCPT ); Wed, 2 Dec 2020 10:19:33 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB8DC061A49 for ; Wed, 2 Dec 2020 07:18:52 -0800 (PST) Received: from lupine.hi.pengutronix.de ([2001:67c:670:100:3ad5:47ff:feaf:1a17] helo=lupine) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkTu0-0007l1-PA; Wed, 02 Dec 2020 16:18:44 +0100 Received: from pza by lupine with local (Exim 4.92) (envelope-from ) id 1kkTu0-0007Qi-7W; Wed, 02 Dec 2020 16:18:44 +0100 Message-ID: <2dfd7785da904e9b518a0e7579d4db79a0b19276.camel@pengutronix.de> Subject: Re: [PATCH v5 08/10] media: Quit parsing stream if doesn't start with SOI From: Philipp Zabel To: "Mirela Rabulea (OSS)" , mchehab@kernel.org, hverkuil-cisco@xs4all.nl, shawnguo@kernel.org, robh+dt@kernel.org Cc: paul.kocialkowski@bootlin.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, s.hauer@pengutronix.de, aisheng.dong@nxp.com, daniel.baluta@nxp.com, robert.chiras@nxp.com, laurentiu.palcu@nxp.com, mark.rutland@arm.com, devicetree@vger.kernel.org, ezequiel@collabora.com, laurent.pinchart+renesas@ideasonboard.com, niklas.soderlund+renesas@ragnatech.se, dafna.hirschfeld@collabora.com, Mirela Rabulea Date: Wed, 02 Dec 2020 16:18:44 +0100 In-Reply-To: <20201112030557.8540-9-mirela.rabulea@oss.nxp.com> References: <20201112030557.8540-1-mirela.rabulea@oss.nxp.com> <20201112030557.8540-9-mirela.rabulea@oss.nxp.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.30.5-1.1 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:3ad5:47ff:feaf:1a17 X-SA-Exim-Mail-From: p.zabel@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-11-12 at 05:05 +0200, Mirela Rabulea (OSS) wrote: > From: Mirela Rabulea > > In the case we get an invalid stream, such as from v4l2-compliance > streaming test, jpeg_next_marker will end up parsing the entire > stream. The standard describes the high level syntax of a jpeg > as starting with SOI, ending with EOI, so return error if the very > first 2 bytes are not SOI. > > Signed-off-by: Mirela Rabulea > --- > drivers/media/v4l2-core/v4l2-jpeg.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c > index 3181ce544f79..d77e04083d57 100644 > --- a/drivers/media/v4l2-core/v4l2-jpeg.c > +++ b/drivers/media/v4l2-core/v4l2-jpeg.c > @@ -499,11 +499,8 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out) > out->num_dht = 0; > out->num_dqt = 0; > > - /* the first marker must be SOI */ > - marker = jpeg_next_marker(&stream); > - if (marker < 0) > - return marker; > - if (marker != SOI) > + /* the first bytes must be SOI, B.2.1 High-level syntax */ > + if (jpeg_get_word_be(&stream) != SOI) > return -EINVAL; > > /* init value to signal if this marker is not present */ Yes, shorter, potentially faster code, and it adheres to the specification more strictly. Reviewed-by: Philipp Zabel regards Philipp