From 39ba0ee6045a68e657e074d8290b4b77baae72c0 Mon Sep 17 00:00:00 2001 From: Andrzej Hunt Date: Fri, 4 Jun 2021 18:25:19 +0200 Subject: [PATCH] zlib: slide_hash: add MSAN annotation to suppress known read from uninitialised memory slide_hash knowingly reads (possibly) uninitialised memory, see comment lower down about prev[n] potentially being garbage. In this case, the result is never used - so we don't care about MSAN complaining about this read. By adding the no_sanitize("memory") attribute, clients of zlib won't see this (unnecessary) error when building and running with MemorySanitizer. An alternative approach is for clients to build zlib with -fsanitize-ignorelist=... where the ignorelist contains something like 'fun:slide_hash'. But that's more work and needs to be redone for any and all CI systems running a given project with MSAN. Adding this annotation to zlib's sources is overall more convenient - but also won't affect non-MSAN builds. This specific issue was found while running git's test suite, but has also been reported by other clients, see e.g. #518. --- deps/zlib/deflate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deps/zlib/deflate.c b/deps/zlib/deflate.c index 799fb93cc..feacd7832 100644 --- a/deps/zlib/deflate.c +++ b/deps/zlib/deflate.c @@ -201,6 +201,11 @@ local const config configuration_table[10] = { * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) +__attribute__((no_sanitize("memory"))) +# endif +#endif local void slide_hash(s) deflate_state *s; {