From: Vsevolod Stakhov Date: Thu, 29 Jan 2026 16:53:59 +0000 (+0000) Subject: [Fix] lua_hs_cache: add defensive checks for zstd_decompress X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dbc6d32b8658ac7bb97b77cee1f0968f5cef11d;p=thirdparty%2Frspamd.git [Fix] lua_hs_cache: add defensive checks for zstd_decompress Add type checking before decompression to catch unexpected data types from Redis. Wrap zstd_decompress in pcall to gracefully handle any errors and provide detailed diagnostic logging when failures occur. --- diff --git a/lualib/lua_hs_cache.lua b/lualib/lua_hs_cache.lua index 96e2a5fa29..d60a1cf9cb 100644 --- a/lualib/lua_hs_cache.lua +++ b/lualib/lua_hs_cache.lua @@ -531,7 +531,22 @@ function redis_backend:load(cache_key, platform_id, callback) else -- Decompress if needed if self.use_compression then - local decompress_err, decompressed = rspamd_util.zstd_decompress(data) + -- Defensive check: ensure data is a string or text before decompression + local data_type = type(data) + if data_type ~= 'string' and data_type ~= 'userdata' then + logger.errx(self.config, "redis GET returned unexpected type %s for key %s, data=%s", + data_type, key, tostring(data)) + callback("unexpected data type: " .. data_type, nil) + return + end + local ok, decompress_err, decompressed = pcall(rspamd_util.zstd_decompress, data) + if not ok then + -- pcall failed - decompress_err contains the error message + logger.errx(self.config, "zstd_decompress pcall failed for key %s: %s, data type=%s, len=%s", + key, tostring(decompress_err), data_type, data_type == 'string' and #data or 'N/A') + callback("decompression error: " .. tostring(decompress_err), nil) + return + end if not decompress_err and decompressed then lua_util.debugm(N, self.config, "redis loaded and decompressed %d -> %d bytes from key %s (compression ratio: %.1f%%)", #data, #decompressed, key, (1 - #data / #decompressed) * 100)