]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix UB in inffast.c when not using window
authorOri Livneh <ori.livneh@gmail.com>
Mon, 23 Aug 2021 16:40:19 +0000 (12:40 -0400)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 22 Sep 2021 14:07:40 +0000 (16:07 +0200)
When not using window, `window + wsize` applies a zero offset to a null pointer, which is undefined behavior.

inffast.c

index de71271b2cb1828a35e24ea90e854539d8164251..2c3add3a84df224bbd2a7a030f7d56a0c3e3d54f 100644 (file)
--- a/inffast.c
+++ b/inffast.c
@@ -155,7 +155,7 @@ void Z_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start) {
     /* Detect if out and window point to the same memory allocation. In this instance it is
        necessary to use safe chunk copy functions to prevent overwriting the window. If the
        window is overwritten then future matches with far distances will fail to copy correctly. */
-    extra_safe = (out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);
+    extra_safe = (wsize != 0 && out >= window && out + INFLATE_FAST_MIN_LEFT <= window + wsize);
 
     /* decode literals and length/distances until end-of-block or not enough
        input data or output space */