From patchwork Mon May 17 21:20:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Marcos_Costa?= X-Patchwork-Id: 1479876 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Qr95cp/d; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FkXBJ4Ztwz9sW8 for ; Tue, 18 May 2021 07:21:28 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6A89A82D05; Mon, 17 May 2021 23:21:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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=gmail.com header.i=@gmail.com header.b="Qr95cp/d"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B66DB82D05; Mon, 17 May 2021 23:21:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 91D4182B71 for ; Mon, 17 May 2021 23:21:12 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jmcosta944@gmail.com Received: by mail-qv1-xf2f.google.com with SMTP id e8so645849qvp.7 for ; Mon, 17 May 2021 14:21:12 -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:mime-version :content-transfer-encoding; bh=qrcgoXFk+xBU60OVozZYIEb5jbtc734DnoMGd8B2Sq8=; b=Qr95cp/dbcuLxrqq1AnxT+mYXt6eFLveze+BRTcIZSCQsdHgooqGvib66a9Uc4Jkov XYXlHyBhaRxkA/ysgakFtR5N9SNjXujCJD+jfRFMGTCi61magswpuolDQIu5LTrXhARn xkghn/arKR57bPPqHwqETCI+FxgbvxZUImW1vC2eQbrhZAkiVpBHJt2dqU5n42KIshZC Q26XlRxnlqwuDJ7LrksvkilxLnZgkBnIa8cXz/co4bcKtMpr0lOL03ZDBPx/ntTmgaIF wyUgDWM6gUsdNatEeJfQAb6bNFmDwUbji8YOBBqyCHE6ecYVuBM6ySGDW3Ibc15mctwQ LK3A== 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:mime-version :content-transfer-encoding; bh=qrcgoXFk+xBU60OVozZYIEb5jbtc734DnoMGd8B2Sq8=; b=RkvCt7izO7DGfrBpCkfOfyYcbR86tTwhVldUiN2k6DaECmZT6o2Q2Pltr7Z1vqYqDx RN2607znbgop4Att3kiE4t1/kdZn7b6WJrlhxuZL6K7Ejon4T2/Yluobbv4RNu2Nh8w3 IMZZZjWU46fK9hsiSms3glr4bQ8TVz0eAmkUSdHbk7wP9WR2IFv+qBXSYE5J6wGV8tCp lqtt9fHrHLfII3Teemd+5FyhR6+S2dyFkdSzhpDebkvmp6g+YvluhPiST5Nlsun4gXco iSlMBq0SkPMQJn/R5JRDDK934YcZoJM5K0MmDd5wXlcF9GA8Tv2LI9iAhmkwxuZkYGPw MTIA== X-Gm-Message-State: AOAM533riiLM2YfaeKerqQqyXMFCEbTz913sX87g5gMU7F/bRXGwkPpx To14OZyJI65OX9RKXKb1lp88p2banNbxU6RJ X-Google-Smtp-Source: ABdhPJzTGHkkVNsax+FTBSfYmQcTSQh3LDEfQhUSyzUAfxxhsCujztSvcVzDdsve8BguflVpMp42DA== X-Received: by 2002:ad4:5c88:: with SMTP id o8mr1797043qvh.38.1621286471259; Mon, 17 May 2021 14:21:11 -0700 (PDT) Received: from localhost.localdomain ([177.194.32.83]) by smtp.googlemail.com with ESMTPSA id n17sm11430055qke.14.2021.05.17.14.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 14:21:11 -0700 (PDT) From: Joao Marcos Costa To: u-boot@lists.denx.de Cc: thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com, richard.genoud@posteo.net, Joao Marcos Costa Subject: [PATCH] fs/squashfs: fix reading of fragmented files Date: Mon, 17 May 2021 18:20:38 -0300 Message-Id: <20210517212038.117284-1-jmcosta944@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean The fragmented files were not correctly read because of two issues: - The squashfs_file_info struct has a field named 'comp', which tells if the file's fragment is compressed or not. This field was always set to 'true' in sqfs_get_regfile_info and sqfs_get_lregfile_info. It should actually take sqfs_frag_lookup's return value. This patch addresses these two assignments. - In sqfs_read, the fragments (compressed or not) were copied to the output buffer through a for loop which was reading data at the wrong offset. Replace these loops by equivalent calls to memcpy, with the right parameters. I tested this patch by comparing the MD5 checksum of a few fragmented files with the respective md5sum output in sandbox, considering both compressed and uncompressed fragments. Signed-off-by: Joao Marcos Costa Tested-by: Richard Genoud Reviewed-by: Miquel Raynal --- fs/squashfs/sqfs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 29805c3c6f..22ef4f2691 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -1253,7 +1253,7 @@ static int sqfs_get_regfile_info(struct squashfs_reg_inode *reg, fentry); if (ret < 0) return -EINVAL; - finfo->comp = true; + finfo->comp = ret; if (fentry->size < 1 || fentry->start == 0x7FFFFFFF) return -EINVAL; } else { @@ -1291,7 +1291,7 @@ static int sqfs_get_lregfile_info(struct squashfs_lreg_inode *lreg, fentry); if (ret < 0) return -EINVAL; - finfo->comp = true; + finfo->comp = ret; if (fentry->size < 1 || fentry->start == 0x7FFFFFFF) return -EINVAL; } else { @@ -1547,20 +1547,16 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, goto out; } - for (j = *actread; j < finfo.size; j++) { - memcpy(buf + j, &fragment_block[finfo.offset + j], 1); - (*actread)++; - } + memcpy(buf + *actread, &fragment_block[finfo.offset], finfo.size - *actread); + *actread = finfo.size; free(fragment_block); } else if (finfo.frag && !finfo.comp) { fragment_block = (void *)fragment + table_offset; - for (j = *actread; j < finfo.size; j++) { - memcpy(buf + j, &fragment_block[finfo.offset + j], 1); - (*actread)++; - } + memcpy(buf + *actread, &fragment_block[finfo.offset], finfo.size - *actread); + *actread = finfo.size; } out: