state->window = (unsigned char *)ZALLOC_WINDOW(state->strm, wsize + state->chunksize, sizeof(unsigned char));
if (state->window == NULL)
return Z_MEM_ERROR;
- memset(state->window + wsize, 0, state->chunksize);
+#ifdef Z_MEMORY_SANITIZER
+ /* This is _not_ to subvert the memory sanitizer but to instead unposion some
+ data we willingly and purposefully load uninitialized into vector registers
+ in order to safely read the last < chunksize bytes of the window. */
+ __msan_unpoison(state->window + wsize, state->chunksize);
+#endif
}
/* if window not in use yet, initialize */
# define zmemcmp_8(str1, str2) memcmp(str1, str2, 8)
#endif
+#if defined(__has_feature)
+# if __has_feature(memory_sanitizer)
+# define Z_MEMORY_SANITIZER 1
+# include <sanitizer/msan_interface.h>
+# endif
+#endif
+
#endif