[PATCH] D108747: [llvm][ProfileData] Add a warning to indicate potentially corrupted data
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 25 20:40:23 PDT 2021
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr, grimar, davidxl, dblaikie.
leonardchan added a project: LLVM.
Herald added a subscriber: hiraditya.
leonardchan requested review of this revision.
This is meant to address PR51628 where we hit an OOM error when accidentally uncompressing corrupted raw profile data. Ideally, there would be some warning or indicator of why this occurred rather than just failing with OOM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D108747
Files:
llvm/lib/ProfileData/InstrProf.cpp
Index: llvm/lib/ProfileData/InstrProf.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProf.cpp
+++ llvm/lib/ProfileData/InstrProf.cpp
@@ -472,6 +472,26 @@
if (!llvm::zlib::isAvailable())
return make_error<InstrProfError>(instrprof_error::zlib_unavailable);
+ // Sanity-check the uncompressed size. If the data is corrupted, then we
+ // could run into a situation where we attempt to malloc a large amount of
+ // data and OOM (see PR51628). While we technically do not have a way to
+ // error-check if the size is actually "correct", we can at least guess
+ // beforehand if the data is corrupt by comparing the uncompressed size to
+ // the compressed size. If the ratio is large enough, then we can warn.
+ //
+ // https://zlib.net/zlib_tech.html stats that typical zlib compression
+ // factors are in the range of 2:1 and 5:1. The value used here should be
+ // large enough such that we minimize the number of "false positives" from
+ // decompressions that we can properly allocate for.
+ constexpr size_t CompressionRatio = 10;
+ if (UncompressedSize > CompressedSize * CompressionRatio) {
+ llvm::errs()
+ << "warning: the uncompressed size is more than "
+ << CompressionRatio
+ << "x the size of the compressed size, which could indicate data "
+ "corruption in the uncompressed size and lead to an OOM error\n";
+ }
+
StringRef CompressedNameStrings(reinterpret_cast<const char *>(P),
CompressedSize);
if (Error E =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108747.368799.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210826/aef0eff0/attachment.bin>
More information about the llvm-commits
mailing list