Skip to contentSkip to conversation

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

PATCH In review Utkal Singh 3 participants 4 messages Mar 19 – Mar 20 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: return error on ZSTD decompression length mismatch

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.

---
 lib/decompress.c | 1 +
 1 file changed, 1 insertion(+)
lib/decompress.c +1 -0
index 3e7a173..ef1271c 100644
@@ -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)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 4 lines · Utkal Singh

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.

Quoted 8 lines

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.

Please stop resending the patch without any modification.