diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2017-09-05 11:21:38 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2017-09-05 11:21:38 +0000 |
commit | 0992d3827739efeb8a6466dd5002aa31264ecb43 (patch) | |
tree | 587de06ce6f6270e27a536cc50d9772a8641fb12 /llvm/lib/Object/Decompressor.cpp | |
parent | 108f36d5b96d0cbf5bfa51b98a2e22c4cb476bdc (diff) | |
download | bcm5719-llvm-0992d3827739efeb8a6466dd5002aa31264ecb43.tar.gz bcm5719-llvm-0992d3827739efeb8a6466dd5002aa31264ecb43.zip |
[Decompression] Fail gracefully when out of memory
This patch adds failing gracefully when running out of memory when
allocating a buffer for decompression.
This provides a work-around for:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3224
Differential revision: https://reviews.llvm.org/D37447
llvm-svn: 312526
Diffstat (limited to 'llvm/lib/Object/Decompressor.cpp')
-rw-r--r-- | llvm/lib/Object/Decompressor.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/Object/Decompressor.cpp b/llvm/lib/Object/Decompressor.cpp index 53f084d7620..89821822484 100644 --- a/llvm/lib/Object/Decompressor.cpp +++ b/llvm/lib/Object/Decompressor.cpp @@ -23,7 +23,7 @@ Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data, if (!zlib::isAvailable()) return createError("zlib is not available"); - Decompressor D(Data); + Decompressor D(Name, Data); Error Err = isGnuStyle(Name) ? D.consumeCompressedGnuHeader() : D.consumeCompressedZLibHeader(Is64Bit, IsLE); if (Err) @@ -31,8 +31,8 @@ Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data, return D; } -Decompressor::Decompressor(StringRef Data) - : SectionData(Data), DecompressedSize(0) {} +Decompressor::Decompressor(StringRef Name, StringRef Data) + : SectionName(Name), SectionData(Data), DecompressedSize(0) {} Error Decompressor::consumeCompressedGnuHeader() { if (!SectionData.startswith("ZLIB")) @@ -92,3 +92,11 @@ Error Decompressor::decompress(MutableArrayRef<char> Buffer) { size_t Size = Buffer.size(); return zlib::uncompress(SectionData, Buffer.data(), Size); } + +void Decompressor::outOfMemoryHandler(void *Data, const std::string &Message, + bool) { + const auto *D = static_cast<const Decompressor *>(Data); + report_fatal_error("decompression of '" + Twine(D->SectionName) + + "' failed: unable to allocate " + + Twine(D->DecompressedSize) + " bytes."); +} |