]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Handle complete overlap in chunkcopy_safe
authorFabian Vogt <fvogt@suse.de>
Tue, 27 Jun 2023 07:47:04 +0000 (09:47 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 28 Jun 2023 15:22:11 +0000 (17:22 +0200)
Fixes #1525

inflate_p.h

index a007cd05df199cbd77865c54b2471349550adc1a..eff73876daf25efad8a627c0df43c2605de564dd 100644 (file)
@@ -161,6 +161,11 @@ static inline uint8_t* chunkcopy_safe(uint8_t *out, uint8_t *from, uint64_t len,
         return out + len;
     }
 
+    /* Complete overlap: Source == destination */
+    if (out == from) {
+        return out + len;
+    }
+
     /* We are emulating a self-modifying copy loop here. To do this in a way that doesn't produce undefined behavior,
      * we have to get a bit clever. First if the overlap is such that src falls between dst and dst+len, we can do the
      * initial bulk memcpy of the nonoverlapping region. Then, we can leverage the size of this to determine the safest