Skip to contentSkip to conversation

erofs-utils: lib: fix missing -EIO in z_erofs_decompress_zstd

PATCH New Utkal Singh 1 participant 1 message Mar 14 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix missing -EIO in z_erofs_decompress_zstd

When ZSTD_decompress() produces fewer bytes than expected, the error path logged an error and did 'goto out' without setting ret to -EIO. The caller in data.c checks (ret < 0), so a positive ret was silently treated as success, potentially consuming corrupted data without any error being propagated.

Set ret = -EIO before the jump, and add an explicit ret = 0 on the success path for symmetry with other decompressors.

Fixes ed2f7cf ("erofs-utils: add preliminary zstd support [x]")
---
 lib/decompress.c | 2 ++
 1 file changed, 2 insertions(+)
lib/decompress.c +2 -0
index 3e7a173..01f5e24 100644
@@ -68,11 +68,13 @@ 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)
 		memcpy(rq->out, dest + rq->decodedskip,
 		       rq->decodedlength - rq->decodedskip);
+	ret = 0;
 out:
 	if (buff)
 		free(buff);
Signature · 1 line
2.43.0