[llvm] 5ed09d5 - [Support] Check zstd decompress result before msan unpoison (#117276)

via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 24 16:59:20 PST 2024


Author: Wu Yingcong
Date: 2024-11-25T08:59:17+08:00
New Revision: 5ed09d552d51825e495aebf38988beba83dbbca9

URL: https://github.com/llvm/llvm-project/commit/5ed09d552d51825e495aebf38988beba83dbbca9
DIFF: https://github.com/llvm/llvm-project/commit/5ed09d552d51825e495aebf38988beba83dbbca9.diff

LOG: [Support] Check zstd decompress result before msan unpoison (#117276)

We should check the zstd decompress result before doing the msan
unpoison. If the res is abnormal, then it would be a huge number, which
will cause undesired msan unpoison behavior and will run for a long
time.

Added: 
    

Modified: 
    llvm/lib/Support/Compression.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Compression.cpp b/llvm/lib/Support/Compression.cpp
index badaf68ab59cd0..3979ca6acaf74e 100644
--- a/llvm/lib/Support/Compression.cpp
+++ b/llvm/lib/Support/Compression.cpp
@@ -206,12 +206,13 @@ Error zstd::decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
   const size_t Res = ::ZSTD_decompress(
       Output, UncompressedSize, (const uint8_t *)Input.data(), Input.size());
   UncompressedSize = Res;
+  if (ZSTD_isError(Res))
+    return make_error<StringError>(ZSTD_getErrorName(Res),
+                                   inconvertibleErrorCode());
   // Tell MemorySanitizer that zstd output buffer is fully initialized.
   // This avoids a false report when running LLVM with uninstrumented ZLib.
   __msan_unpoison(Output, UncompressedSize);
-  return ZSTD_isError(Res) ? make_error<StringError>(ZSTD_getErrorName(Res),
-                                                     inconvertibleErrorCode())
-                           : Error::success();
+  return Error::success();
 }
 
 Error zstd::decompress(ArrayRef<uint8_t> Input,


        


More information about the llvm-commits mailing list