From: Fabian Vogt Date: Tue, 27 Jun 2023 07:47:04 +0000 (+0200) Subject: Handle complete overlap in chunkcopy_safe X-Git-Tag: 2.1.3~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5a4a8ae6b5898689389fc7c874759c9b9328251;p=thirdparty%2Fzlib-ng.git Handle complete overlap in chunkcopy_safe Fixes #1525 --- diff --git a/inflate_p.h b/inflate_p.h index a007cd05d..eff73876d 100644 --- a/inflate_p.h +++ b/inflate_p.h @@ -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