Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4358772ybv; Tue, 25 Feb 2020 18:33:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzBdKah3+zOuB6sEGputmdVP/CiCksBOhilmXOrvi7Rpg8VpJOOhNIoRscySj5Y083jh/Q+ X-Received: by 2002:aca:d483:: with SMTP id l125mr1407953oig.124.1582684434338; Tue, 25 Feb 2020 18:33:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582684434; cv=none; d=google.com; s=arc-20160816; b=zPzRChd91u4qaFgvypW//41XTb0FXt9mFdD5u2XgOkU2Oh7Nj6yZy5ymI/2IZSLtdI M68kntE3/gBZ0m59ZfKTXy9XFxk3W/+ZB4JAR4vhAONvSsoKYQL9hmXKz6GHhXOXYx3y +K5ioRCjOnESUg+QLGT+stSbtvK/Gr78u5cHDXiYwBOaHN+D+pZlfxjFixC59y3usbxB /jVWSFGoQPtYmMEwirK4cohNWLtjA6r1Qh3rm6elWhcDWvqSTJs6SbDxzdSLeGsyZ5c+ dHXd4foe9F6yifjMYobWypcgCIHV2XYRFlz4A/MG1mzasw1z26bOefICaC2Aac6RXIIf jq/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=3zFoh5XAAcBWpZA8nGu9Fl+0ps30XV5K60UWWFohtW4=; b=K2Yy0tZTHamUWZn91NZ07M+baqYFYfHXg8OwGowBRfEukwRMJuWl82Lu5BTDz+eOMT AP7GfBoC263X1RuzRx9U8yTvz7hYGRnJ9lzeKUYP7tDY9ks3pcK75OeT4BPfNgnUgIpN iYYHfjFqUYPRNSo1/rIvs3EF00wD8iZRxMFUCUUSa3Bl7fHWq7+iSsTh2ueJ4CH+TBoa MQEvbNa2Wyop5IL2x/moVhPOUo/264W5eKP2iqUUUUkj82t6eOJys7y3QUHa9qZxRRD/ K7vW+Np2ngbDv/PlO6P5hELzvADTo6rhBiF3C2FI+3DDziNZjnaIO6hTgKdrNapBP1bW UYQA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si483726otn.232.2020.02.25.18.33.42; Tue, 25 Feb 2020 18:33:54 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730135AbgBZCbr (ORCPT + 99 others); Tue, 25 Feb 2020 21:31:47 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:51498 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727880AbgBZCbq (ORCPT ); Tue, 25 Feb 2020 21:31:46 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 39D62DD8C58A4B46E2CF; Wed, 26 Feb 2020 10:31:45 +0800 (CST) Received: from architecture4.huawei.com (10.160.196.180) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 26 Feb 2020 10:31:39 +0800 From: Gao Xiang To: Chao Yu , CC: LKML , Miao Xie , "Gao Xiang" , Lasse Collin Subject: [PATCH 2/3] erofs: use LZ4_decompress_safe() for full decoding Date: Wed, 26 Feb 2020 10:30:10 +0800 Message-ID: <20200226023011.103798-2-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200226023011.103798-1-gaoxiang25@huawei.com> References: <20200226023011.103798-1-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.160.196.180] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As Lasse pointed out, "EROFS uses LZ4_decompress_safe_partial for both partial and full blocks. Thus when it is decoding a full block, it doesn't know if the LZ4 decoder actually decoded all the input. The real uncompressed size could be bigger than the value stored in the file system metadata. Using LZ4_decompress_safe instead of _safe_partial when decompressing a full block would help to detect errors." So it's reasonable to use _safe in case of corrupted images and it might have some speed gain as well although I didn't observe much difference. Cc: Lasse Collin Signed-off-by: Gao Xiang --- fs/erofs/decompressor.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 5779a15c2cd6..c77cec4327fa 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -157,9 +157,14 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) } } - ret = LZ4_decompress_safe_partial(src + inputmargin, out, - inlen, rq->outputsize, - rq->outputsize); + if (rq->partial_decoding) + ret = LZ4_decompress_safe_partial(src + inputmargin, out, + inlen, rq->outputsize, + rq->outputsize); + else + ret = LZ4_decompress_safe(src + inputmargin, out, + inlen, rq->outputsize); + if (ret < 0) { erofs_err(rq->sb, "failed to decompress, in[%u, %u] out[%u]", inlen, inputmargin, rq->outputsize); -- 2.17.1