From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17667C61D97 for ; Sun, 29 Jan 2023 16:44:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C8D6685742; Sun, 29 Jan 2023 17:44:39 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="jSnNG+ao"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 62C3185351; Sun, 29 Jan 2023 17:44:35 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D046285518 for ; Sun, 29 Jan 2023 17:44:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6E5F9B808CD; Sun, 29 Jan 2023 16:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02315C433EF; Sun, 29 Jan 2023 16:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675010671; bh=BiSE51LAqHXQhy/P2zsIUnzGMNYEPSAuMpjNLV381Rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jSnNG+aoeVqaP0xsW19bukc18AKnze44Ou3DvlL7U5ZiBAjT+eieEMI2x/gwD2WYT v7YvQTJHtGPiawddiApC2jr1FPj2jAr8torjB/nArabouHMBjoYQ/8qS0bJ08O1LlQ LkaD9a6uagb7O7B+rjJ+xXdhrMq6ess1VKWlXEhqSZKJSfdNNe51GT3+8NDZOUwPgw MHlDgixyU0WLm9lZGN6iMT3q34uNXb41TjFg2JRRYk02SZ9AIvpD/KVNEDzlhYXvrm x4jIGmOgg1tgz4EDX7tJkKRBwPt0/GzAvpZCeZmknleLODLqKCC/hcf8GXeMcupHYt rd3J1NAqrlaHA== Received: by pali.im (Postfix) id 60474B73; Sun, 29 Jan 2023 17:44:28 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Simon Glass Cc: u-boot@lists.denx.de Subject: [PATCH u-boot 2/2] tools: default_image: Accept images with padding Date: Sun, 29 Jan 2023 17:44:11 +0100 Message-Id: <20230129164411.9795-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230129164411.9795-1-pali@kernel.org> References: <20230129164411.9795-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean If image file is stored on flash partition then it contains padding, which is not part of the image itself. Image data size is stored in the image header. So use image size from the header instead of expecting that total image file size is size of the header plus size of the image data. This allows dumpimage to parse image files with padding (e.g. dumped from flash partition). Signed-off-by: Pali Rohár --- tools/default_image.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/default_image.c b/tools/default_image.c index 4aa9a33241cb..0996e1dfe9c8 100644 --- a/tools/default_image.c +++ b/tools/default_image.c @@ -81,7 +81,13 @@ static int image_verify_header(unsigned char *ptr, int image_size, } data = (const unsigned char *)ptr + sizeof(struct legacy_img_hdr); - len = image_size - sizeof(struct legacy_img_hdr); + len = image_get_data_size(hdr); + + if (image_size - sizeof(struct legacy_img_hdr) < len) { + debug("%s: Bad image size: \"%s\" is no valid image\n", + params->cmdname, params->imagefile); + return -FDT_ERR_BADSTRUCTURE; + } checksum = be32_to_cpu(hdr->ih_dcrc); if (crc32(0, data, len) != checksum) { -- 2.20.1