]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
riscv: chunkset_rvv: fix SIGSEGV in CHUNKCOPY
authorIcenowy Zheng <uwu@icenowy.me>
Mon, 24 Mar 2025 08:50:37 +0000 (16:50 +0800)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Sat, 26 Jul 2025 18:37:39 +0000 (20:37 +0200)
The chunkset_tpl comment allows negative dist (out - from) as long as
the length is smaller than the absolute value of dist (i.e. memory does
not overlap). However this case is currently broken in the RVV override
of CHUNKCOPY -- it compares dist (which is a ptrdiff_t, a value that
should be of the same size with size_t but signed) with the result of
sizeof (which is a size_t), and this triggers the implicit conversion
from signed to unsigned (thus losing negative values).

As it's promised to be not overlapping when dist is negative, just use a
gaint memcpy() call to copy everything.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
arch/riscv/chunkset_rvv.c

index ee43bde2f71d81b3e6f9b2d03ae13a7dec7ff7b1..e0915dfc9666e5a788fdc1c7307990a383b3b94e 100644 (file)
@@ -92,7 +92,7 @@ static inline uint8_t* CHUNKCOPY(uint8_t *out, uint8_t const *from, unsigned len
     from += align;
     len -= align;
     ptrdiff_t dist = out - from;
-    if (dist >= len) {
+    if (dist < 0 || dist >= len) {
         memcpy(out, from, len);
         out += len;
         from += len;