From: Nathan Moinvaziri Date: Mon, 11 Apr 2022 02:35:12 +0000 (-0700) Subject: Use _msan_unposion to unposion end of window for when it needs to read the past ... X-Git-Tag: 2.1.0-beta1~273 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c882034d48afc0b32a38e8f7ca63a2e4e91ab42d;p=thirdparty%2Fzlib-ng.git 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 --- diff --git a/inflate.c b/inflate.c index 1a091485..291582d0 100644 --- a/inflate.c +++ b/inflate.c @@ -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 */ diff --git a/zbuild.h b/zbuild.h index f6923853..9274cbc1 100644 --- a/zbuild.h +++ b/zbuild.h @@ -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 +# endif +#endif + #endif