From: Nathan Moinvaziri Date: Tue, 20 Jan 2026 00:45:53 +0000 (-0800) Subject: Simplify logic in INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d9dbe97c308930a7fb339c38e581a8059d36175;p=thirdparty%2Fzlib-ng.git Simplify logic in INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR --- diff --git a/inffast_tpl.h b/inffast_tpl.h index 8247b833d..6918ec194 100644 --- a/inffast_tpl.h +++ b/inffast_tpl.h @@ -200,21 +200,16 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) { SET_BAD("invalid distance too far back"); break; } - if (len <= op - whave) { - do { - *out++ = 0; - } while (--len); + unsigned gap = op - whave; + unsigned zeros = MIN(len, gap); + memset(out, 0, zeros); /* fill missing bytes with zeros */ + out += zeros; + len -= zeros; + if (len == 0) continue; - } - len -= op - whave; - do { - *out++ = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - *out++ = *from++; - } while (--len); + op = whave; + if (op == 0) { /* copy from already-decoded output */ + out = chunkcopy_safe(out, out - dist, len, safe); continue; } #else