]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use _msan_unposion to unposion end of window for when it needs to read the past ...
authorNathan Moinvaziri <nathan@nathanm.com>
Mon, 11 Apr 2022 02:35:12 +0000 (19:35 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 17 Mar 2023 20:27:56 +0000 (21:27 +0100)
Co-authored-by: Adam Stylinski <kungfujesus06@gmail.com>
Backported from commit c882034d48afc0b32a38e8f7ca63a2e4e91ab42d.

inflate.c
zbuild.h

index 3990eb3d91f00c2c43db5ee55c733493dad76d4b..75491b7fc87c3a3321deccf39fb5ff7894b18df0 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -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 */
index f0f9202cbfadae144659c5db60f67153587f96b5..17f98101a43dc7f29d836317dde0fccc173baf8d 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 /* 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