state->window = (unsigned char *) ZALLOC_WINDOW(state->strm, wsize + state->chunksize, sizeof(unsigned char));
if (state->window == Z_NULL)
return 1;
- 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 */
/* Ignore unused variable warning */
#define Z_UNUSED(var) (void)(var)
+#if defined(__has_feature)
+# if __has_feature(memory_sanitizer)
+# define Z_MEMORY_SANITIZER 1
+# include <sanitizer/msan_interface.h>
+# endif
+#endif
+
#endif