From: Nick Terrell Date: Tue, 29 Oct 2019 00:51:17 +0000 (-0700) Subject: Fix assert in ZSTD_safecopy X-Git-Tag: v1.4.4~1^2~6^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1856%2Fhead;p=thirdparty%2Fzstd.git Fix assert in ZSTD_safecopy In the case that `op >= oend_w` it is possible that `diff < 8` because the two buffers could be adjacent. Credit to OSS-Fuzz, which found the bug. It isn't reproducible because it depends on the memory layout. --- diff --git a/lib/decompress/zstd_decompress_block.c b/lib/decompress/zstd_decompress_block.c index cbb66c8db..767e5f9a0 100644 --- a/lib/decompress/zstd_decompress_block.c +++ b/lib/decompress/zstd_decompress_block.c @@ -617,7 +617,7 @@ static void ZSTD_safecopy(BYTE* op, BYTE* const oend_w, BYTE const* ip, ptrdiff_ ptrdiff_t const diff = op - ip; BYTE* const oend = op + length; - assert((ovtype == ZSTD_no_overlap && (diff <= -8 || diff >= 8)) || + assert((ovtype == ZSTD_no_overlap && (diff <= -8 || diff >= 8 || op >= oend_w)) || (ovtype == ZSTD_overlap_src_before_dst && diff >= 0)); if (length < 8) {