From bcb73d076b043c34ab88265c2bdddaff8b702cc1 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 12 Dec 2019 10:30:32 +0100 Subject: Fix "buffer to small" being treated as error in zstd compressor The zstd compress function returns an error code if it cannot fit the compressed data into the given destination buffer. This commit adds a check for this error and reports that the libsquashfs compressor implementation was unable to shrink the input instead of claiming a fatal error happened. Signed-off-by: David Oberhollenzer --- lib/sqfs/comp/zstd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sqfs/comp/zstd.c b/lib/sqfs/comp/zstd.c index 3fac85f..a850033 100644 --- a/lib/sqfs/comp/zstd.c +++ b/lib/sqfs/comp/zstd.c @@ -12,6 +12,7 @@ #include #include +#include #include "internal.h" @@ -63,8 +64,12 @@ static sqfs_s32 zstd_comp_block(sqfs_compressor_t *base, const sqfs_u8 *in, ret = ZSTD_compressCCtx(zstd->zctx, out, outsize, in, size, zstd->level); - if (ZSTD_isError(ret)) + if (ZSTD_isError(ret)) { + if (ZSTD_getErrorCode(ret) == ZSTD_error_dstSize_tooSmall) + return 0; + return SQFS_ERROR_COMPRESSOR; + } return ret < size ? ret : 0; } -- cgit v1.2.3