summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Moinvaziri <nathan@nathanm.com>2026-01-19 16:45:53 -0800
committerHans Kristian Rosbach <hk-github@circlestorm.org>2026-02-05 21:39:03 +0100
commit3d9dbe97c308930a7fb339c38e581a8059d36175 (patch)
treee97f07872c534cf1f576d064e3f223d587157996
parentfd0536885c4eefa89b6feedd708a65f7c9988a63 (diff)
downloadProject-Tick-3d9dbe97c308930a7fb339c38e581a8059d36175.tar.gz
Project-Tick-3d9dbe97c308930a7fb339c38e581a8059d36175.zip
Simplify logic in INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
-rw-r--r--inffast_tpl.h23
1 files changed, 9 insertions, 14 deletions
diff --git a/inffast_tpl.h b/inffast_tpl.h
index 8247b833d2..6918ec194b 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