[llvm] [Support] Check zstd decompress result before msan unpoison (PR #117276)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 18:37:11 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Wu Yingcong (yingcong-wu)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/117276.diff


1 Files Affected:

- (modified) llvm/lib/Support/Compression.cpp (+4-3) 


``````````diff
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,

``````````

</details>


https://github.com/llvm/llvm-project/pull/117276


More information about the llvm-commits mailing list