Use _msan_unposion to unposion end of window for when it needs to read the past < chunksize bytes in the window. See #1245.

Co-authored-by: Adam Stylinski <kungfujesus06@gmail.com>
This commit is contained in:
Nathan Moinvaziri 2022-04-10 19:35:12 -07:00 committed by Hans Kristian Rosbach
parent 24d1d8497e
commit c882034d48
2 changed files with 13 additions and 1 deletions

View File

@ -205,7 +205,12 @@ int Z_INTERNAL inflate_ensure_window(struct inflate_state *state) {
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 */

View File

@ -246,4 +246,11 @@
# 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