Commit 5c11e80f3 for clamav.net
commit 5c11e80f3a510194dfa18f72f0d93305714e0409
Author: GitHubArchive\Val S. <218006698+val-ms@users.noreply.github.com>
Date: Fri Nov 20 19:01:37 2026 -0500
libclammspack: Validate LZX match offsets before narrowing
The LZX decoder narrows an unsigned wrapped-window distance to int
before checking it against the window size. Crafted repeated offsets
can narrow to a negative value, bypass the check, and cause an
out-of-bounds copy.
Check the unsigned distance first, then cast only a value bounded by
the window size.
Reported by Feng Xue and XGPT of ThreatBook.
CLAM-3085
diff --git a/libclammspack/mspack/lzxd.c b/libclammspack/mspack/lzxd.c
index f498dba95..fa37f5339 100644
--- a/libclammspack/mspack/lzxd.c
+++ b/libclammspack/mspack/lzxd.c
@@ -627,11 +627,11 @@ int lzxd_decompress(struct lzxd_stream *lzx, off_t out_bytes) {
return lzx->error = MSPACK_ERR_DECRUNCH;
}
/* j = length from match offset to end of window */
- j = match_offset - window_posn;
- if (j > (int) lzx->window_size) {
+ if ((match_offset - window_posn) > lzx->window_size) {
D(("match offset beyond window boundaries"))
return lzx->error = MSPACK_ERR_DECRUNCH;
}
+ j = (int) (match_offset - window_posn);
runsrc = &window[lzx->window_size - j];
if (j < i) {
/* if match goes over the window edge, do two copy runs */