Skip to content

Commit 39ba0ee

Browse files
ahuntethomson
authored andcommitted
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. libgit2#518.
1 parent 6febb7d commit 39ba0ee

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

deps/zlib/deflate.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ local const config configuration_table[10] = {
201201
* bit values at the expense of memory usage). We slide even when level == 0 to
202202
* keep the hash table consistent if we switch back to level > 0 later.
203203
*/
204+
#if defined(__has_feature)
205+
# if __has_feature(memory_sanitizer)
206+
__attribute__((no_sanitize("memory")))
207+
# endif
208+
#endif
204209
local void slide_hash(s)
205210
deflate_state *s;
206211
{

0 commit comments

Comments
 (0)