]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
compress: deal with zstd decoder issues gracefully
authorLennart Poettering <lennart@poettering.net>
Thu, 3 Apr 2025 15:28:11 +0000 (17:28 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 13 May 2025 13:39:57 +0000 (15:39 +0200)
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

src/basic/compress.c

index 5f71eb6853aed7ee25b4b181103b5b3dce7bf1a1..c8096635ef835487f739f11510a79f2ddf23f926 100644 (file)
@@ -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;