From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BBCA2D8792 for ; Fri, 19 Dec 2025 06:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766126633; cv=none; b=qgbYb0LBWlZDLfdkFA9UqAFGTiHY2ZTq0XZmzoJoggt8v/SNrF54EAc1SHSxrdkrrO62nvZgX8fvItRRvk/0n3CWmoWhxgjkvCDq4LVUqgLv/dTkm6uv4ZCRdT/V+sy5j4lik8S4AFaLOqxPoPUlA9Rwo7gwirBHkR9L1MjlQP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766126633; c=relaxed/simple; bh=VUFqMaH8gzHm1GM6ZJsNa0GdbIioys4F8ytuUJSeINM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bqFPz+HNLWKYWffjqEZk1ab1Cxo2FlnRGEV4znXh6VuQWKiSkSo9vp+9m4Z+19B9uMfUYPYE9N4kof16s3v/C0L511sZmKf4lKDtTfHtezsnzyP7wgoQy/c/O4Jwi2eO1G4IL1SbN9SnZVN6ScSzW2yLUXm0ehAW4ErBQQbLrwA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ntSZsBy2; arc=none smtp.client-ip=115.124.30.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ntSZsBy2" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766126621; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=DB9DoLwj8cJ1DkyEcnLVgtFBXXvGE1oUmJ9kmFxl0lE=; b=ntSZsBy2Z0G0CQ67LEoG9x29B070ehWzwYNLscFiZAyDEaML3TpXcybj8/ZiVD5IL+hlhnBTwJ2us9nR20N1zGWMEgJgHUoiLPiSeNrh0wO3iDE6JtbGqaSNgRRVn6CYvFaDT9buoMvwPSo8PSsTgllcKoupQJBllbZKQdk024U= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WvBkRxm_1766126617 cluster:ay36) by smtp.aliyun-inc.com; Fri, 19 Dec 2025 14:43:40 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH] erofs: improve LZ4 error strings Date: Fri, 19 Dec 2025 14:43:36 +0800 Message-ID: <20251219064336.684930-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Just like what was done for other algorithms, let's propagate detailed error reasons for LZ4 instead of just -EFSCORRUPTED to users: "corrupted compressed data": the compressed data is malformed or destination buffer is not large enough "unexpected end of stream": the compressed stream ends normally, but without producing enough decompressed data. "compressed data start not found": can be returned by z_erofs_fixup_insize(). Signed-off-by: Gao Xiang --- fs/erofs/decompressor.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index d5d090276391..fcbb2502dbf0 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -195,26 +195,25 @@ const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, return NULL; } -static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst) +static const char *__z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, + u8 *dst) { - bool support_0padding = false, may_inplace = false; + bool zeropadded = erofs_sb_has_zero_padding(EROFS_SB(rq->sb)); + bool may_inplace = false; unsigned int inputmargin; u8 *out, *headpage, *src; const char *reason; int ret, maptype; - DBG_BUGON(*rq->in == NULL); headpage = kmap_local_page(*rq->in); - /* LZ4 decompression inplace is only safe if zero_padding is enabled */ - if (erofs_sb_has_zero_padding(EROFS_SB(rq->sb))) { - support_0padding = true; + if (zeropadded) { reason = z_erofs_fixup_insize(rq, headpage + rq->pageofs_in, min_t(unsigned int, rq->inputsize, rq->sb->s_blocksize - rq->pageofs_in)); if (reason) { kunmap_local(headpage); - return IS_ERR(reason) ? PTR_ERR(reason) : -EFSCORRUPTED; + return reason; } may_inplace = !((rq->pageofs_in + rq->inputsize) & (rq->sb->s_blocksize - 1)); @@ -224,26 +223,24 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst src = z_erofs_lz4_handle_overlap(rq, headpage, dst, &inputmargin, &maptype, may_inplace); if (IS_ERR(src)) - return PTR_ERR(src); + return ERR_CAST(src); out = dst + rq->pageofs_out; /* legacy format could compress extra data in a pcluster. */ - if (rq->partial_decoding || !support_0padding) + if (rq->partial_decoding || !zeropadded) ret = LZ4_decompress_safe_partial(src + inputmargin, out, rq->inputsize, rq->outputsize, rq->outputsize); else ret = LZ4_decompress_safe(src + inputmargin, out, rq->inputsize, rq->outputsize); + if (ret == rq->outputsize) + reason = NULL; + else if (ret < 0) + reason = "corrupted compressed data"; + else + reason = "unexpected end of stream"; - if (ret != rq->outputsize) { - if (ret >= 0) - memset(out + ret, 0, rq->outputsize - ret); - ret = -EFSCORRUPTED; - } else { - ret = 0; - } - - if (maptype == 0) { + if (!maptype) { kunmap_local(headpage); } else if (maptype == 1) { vm_unmap_ram(src, rq->inpages); @@ -251,15 +248,16 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq, u8 *dst z_erofs_put_gbuf(src); } else if (maptype != 3) { DBG_BUGON(1); - return -EFAULT; + return ERR_PTR(-EFAULT); } - return ret; + return reason; } static const char *z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, struct page **pagepool) { unsigned int dst_maptype; + const char *reason; void *dst; int ret; @@ -283,12 +281,12 @@ static const char *z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, dst_maptype = 2; } } - ret = z_erofs_lz4_decompress_mem(rq, dst); + reason = __z_erofs_lz4_decompress(rq, dst); if (!dst_maptype) kunmap_local(dst); else if (dst_maptype == 2) vm_unmap_ram(dst, rq->outpages); - return ERR_PTR(ret); + return reason; } static const char *z_erofs_transform_plain(struct z_erofs_decompress_req *rq, -- 2.43.5