From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, yifan.yfzhao@foxmail.com,
singhutkal015@gmail.com
Subject: [PATCH v1 2/2] erofs-utils: lib: return error on ZSTD decompression length mismatch
Date: Mon, 16 Mar 2026 21:28:47 +0000 [thread overview]
Message-ID: <20260316212847.57030-3-singhutkal015@gmail.com> (raw)
In-Reply-To: <20260316212847.57030-1-singhutkal015@gmail.com>
When ZSTD_decompress() succeeds but produces a different number of
bytes than expected, the code logs an error and jumps to cleanup.
However, it does not set ret to an error code. Since ret still
holds the positive ZSTD output size, the caller treats it as
success via the 'if (ret < 0)' check in z_erofs_read_one_data(),
causing silently corrupted data to be returned.
Set ret to -EIO before jumping to cleanup, consistent with the
ZSTD_isError() error handling path above.
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/decompress.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/decompress.c b/lib/decompress.c
index fb81039..a27881c 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -75,6 +75,7 @@ static int z_erofs_decompress_zstd(struct z_erofs_decompress_req *rq)
if (ret != (int)total) {
erofs_err("ZSTD decompress length mismatch %d, expected %d",
ret, total);
+ ret = -EIO;
goto out;
}
if (rq->decodedskip || total != rq->decodedlength)
--
2.43.0
prev parent reply other threads:[~2026-03-16 21:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 21:28 [PATCH v1 0/2] erofs-utils: lib: fix ZSTD decompression safety issues Utkal Singh
2026-03-16 21:28 ` [PATCH v1 1/2] erofs-utils: lib: validate ZSTD frame content size in decompression Utkal Singh
2026-03-17 2:10 ` Gao Xiang
2026-03-17 4:47 ` Utkal Singh
2026-03-16 21:28 ` Utkal Singh [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260316212847.57030-3-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=yifan.yfzhao@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox