From: Lennart Poettering Date: Thu, 3 Apr 2025 15:28:11 +0000 (+0200) Subject: compress: deal with zstd decoder issues gracefully X-Git-Tag: v258-rc1~633^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=559795fa4602866ced44fbcc9d914dec6ade09de;p=thirdparty%2Fsystemd.git compress: deal with zstd decoder issues gracefully If zstd frames are corrupted the initial size returned for the current frame might be wrong. Don#t assert() on that, but handle it gracefully, as EBADMSG --- diff --git a/src/basic/compress.c b/src/basic/compress.c index 5f71eb6853a..c8096635ef8 100644 --- a/src/basic/compress.c +++ b/src/basic/compress.c @@ -495,11 +495,10 @@ int decompress_blob_zstd( }; size_t k = sym_ZSTD_decompressStream(dctx, &output, &input); - if (sym_ZSTD_isError(k)) { - log_debug("ZSTD decoder failed: %s", sym_ZSTD_getErrorName(k)); - return zstd_ret_to_errno(k); - } - assert(output.pos >= size); + if (sym_ZSTD_isError(k)) + return log_debug_errno(zstd_ret_to_errno(k), "ZSTD decoder failed: %s", sym_ZSTD_getErrorName(k)); + if (output.pos < size) + return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "ZSTD decoded less data than indicated, probably corrupted stream."); *dst_size = size; return 0;