[PATCH] erofs-utils: lib: return error on ZSTD decompression length mismatch

Utkal Singh singhutkal015 at gmail.com
Thu Mar 19 21:17:21 AEDT 2026


When ZSTD_decompress() returns a size different from the expected
decoded size, the current code logs an error and jumps to cleanup
without setting ret to a negative value.

Since ret still holds a positive byte count, the caller interprets
it as success, potentially treating incorrectly decompressed data
as valid output.

Set ret to -EIO before jumping to cleanup, consistent with the
existing ZSTD_isError() handling above.

Signed-off-by: Utkal Singh <singhutkal015 at gmail.com>
---
 lib/decompress.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/decompress.c b/lib/decompress.c
index 3e7a173..ef1271c 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -68,6 +68,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



More information about the Linux-erofs mailing list