]> 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>
Wed, 13 Apr 2022 22:00:27 +0000 (00:00 +0200)
Co-authored-by: Adam Stylinski <kungfujesus06@gmail.com>
inflate.c
zbuild.h

index 1a0914859b5a31a9a108342821aa649b973c6db8..291582d0579c7d43bd5a2505dd01cf27c4ecf3d1 100644 (file)
--- 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 */
index f6923853441f934d2e36e2d96de763003775befb..9274cbc1ced8dafd2c4423479738766bb26b5313 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 #  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