From 680bdb58f72256f3b71cd0ff9a94f34a31cafd1e Mon Sep 17 00:00:00 2001 From: Jeremy Maitin-Shepard Date: Fri, 17 Feb 2023 14:37:59 -0800 Subject: [PATCH] Suppress MemorySanitizer false positive MemorySanitizer does not support assembly, and therefore produces a false positive on `blake3_hasher_finalize` and related functions. --- c/blake3.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/c/blake3.c b/c/blake3.c index dc343f9..d1fa10b 100644 --- a/c/blake3.c +++ b/c/blake3.c @@ -5,6 +5,13 @@ #include "blake3.h" #include "blake3_impl.h" +#ifdef __has_feature +#if __has_feature(memory_sanitizer) +#include +#define BLAKE3_MEMORY_SANITIZER_BUILD +#endif +#endif + const char *blake3_version(void) { return BLAKE3_VERSION_STRING; } INLINE void chunk_state_init(blake3_chunk_state *self, const uint32_t key[8], @@ -580,6 +587,10 @@ void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, if (self->cv_stack_len == 0) { output_t output = chunk_state_output(&self->chunk); output_root_bytes(&output, seek, out, out_len); +#ifdef BLAKE3_MEMORY_SANITIZER_BUILD + // MemorySanitizer gives a false positive due to use of assembly. + __msan_unpoison(out, out_len); +#endif return; } // If there are any bytes in the chunk state, finalize that chunk and do a @@ -608,6 +619,10 @@ void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, output = parent_output(parent_block, self->key, self->chunk.flags); } output_root_bytes(&output, seek, out, out_len); +#ifdef BLAKE3_MEMORY_SANITIZER_BUILD + // MemorySanitizer gives a false positive due to use of assembly. + __msan_unpoison(out, out_len); +#endif } void blake3_hasher_reset(blake3_hasher *self) {