diff options
author | Nathan Moinvaziri <nathan@nathanm.com> | 2022-04-10 19:35:12 -0700 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2023-03-17 21:27:56 +0100 |
commit | 77bb08ad215f75b0dff9d81a96c20f7001e1ff55 (patch) | |
tree | 5de1a71ace2a24b5f8c801132a073a59ea6b38a9 | |
parent | bc915bf1589d2d5a01d5aab6eff514d58f89bbc7 (diff) |
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>
Backported from commit c882034d48afc0b32a38e8f7ca63a2e4e91ab42d.
-rw-r--r-- | inflate.c | 7 | ||||
-rw-r--r-- | zbuild.h | 7 |
2 files changed, 13 insertions, 1 deletions
@@ -211,7 +211,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 == 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 */ @@ -37,4 +37,11 @@ /* 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 |