mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-09 01:29:52 +00:00
Revert "[Decompression] Fail gracefully when out of memory"
This reverts commit r312526. Revert "Fix test/DebugInfo/dwarfdump-decompression-invalid-size.test" This reverts commit r312527. It causes an ASan failure: http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/4150 llvm-svn: 312582
This commit is contained in:
parent
29c7487167
commit
3ae4170480
@ -13,7 +13,6 @@
|
|||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace object {
|
namespace object {
|
||||||
@ -32,9 +31,7 @@ public:
|
|||||||
/// @brief Resize the buffer and uncompress section data into it.
|
/// @brief Resize the buffer and uncompress section data into it.
|
||||||
/// @param Out Destination buffer.
|
/// @param Out Destination buffer.
|
||||||
template <class T> Error resizeAndDecompress(T &Out) {
|
template <class T> Error resizeAndDecompress(T &Out) {
|
||||||
install_bad_alloc_error_handler(outOfMemoryHandler, this);
|
|
||||||
Out.resize(DecompressedSize);
|
Out.resize(DecompressedSize);
|
||||||
remove_bad_alloc_error_handler();
|
|
||||||
return decompress({Out.data(), (size_t)DecompressedSize});
|
return decompress({Out.data(), (size_t)DecompressedSize});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,14 +52,11 @@ public:
|
|||||||
static bool isGnuStyle(StringRef Name);
|
static bool isGnuStyle(StringRef Name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void outOfMemoryHandler(void *Data, const std::string &Message, bool);
|
Decompressor(StringRef Data);
|
||||||
|
|
||||||
Decompressor(StringRef Name, StringRef Data);
|
|
||||||
|
|
||||||
Error consumeCompressedGnuHeader();
|
Error consumeCompressedGnuHeader();
|
||||||
Error consumeCompressedZLibHeader(bool Is64Bit, bool IsLittleEndian);
|
Error consumeCompressedZLibHeader(bool Is64Bit, bool IsLittleEndian);
|
||||||
|
|
||||||
StringRef SectionName;
|
|
||||||
StringRef SectionData;
|
StringRef SectionData;
|
||||||
uint64_t DecompressedSize;
|
uint64_t DecompressedSize;
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,7 @@ Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data,
|
|||||||
if (!zlib::isAvailable())
|
if (!zlib::isAvailable())
|
||||||
return createError("zlib is not available");
|
return createError("zlib is not available");
|
||||||
|
|
||||||
Decompressor D(Name, Data);
|
Decompressor D(Data);
|
||||||
Error Err = isGnuStyle(Name) ? D.consumeCompressedGnuHeader()
|
Error Err = isGnuStyle(Name) ? D.consumeCompressedGnuHeader()
|
||||||
: D.consumeCompressedZLibHeader(Is64Bit, IsLE);
|
: D.consumeCompressedZLibHeader(Is64Bit, IsLE);
|
||||||
if (Err)
|
if (Err)
|
||||||
@ -31,8 +31,8 @@ Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data,
|
|||||||
return D;
|
return D;
|
||||||
}
|
}
|
||||||
|
|
||||||
Decompressor::Decompressor(StringRef Name, StringRef Data)
|
Decompressor::Decompressor(StringRef Data)
|
||||||
: SectionName(Name), SectionData(Data), DecompressedSize(0) {}
|
: SectionData(Data), DecompressedSize(0) {}
|
||||||
|
|
||||||
Error Decompressor::consumeCompressedGnuHeader() {
|
Error Decompressor::consumeCompressedGnuHeader() {
|
||||||
if (!SectionData.startswith("ZLIB"))
|
if (!SectionData.startswith("ZLIB"))
|
||||||
@ -92,11 +92,3 @@ Error Decompressor::decompress(MutableArrayRef<char> Buffer) {
|
|||||||
size_t Size = Buffer.size();
|
size_t Size = Buffer.size();
|
||||||
return zlib::uncompress(SectionData, Buffer.data(), 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.");
|
|
||||||
}
|
|
||||||
|
Binary file not shown.
@ -1,15 +0,0 @@
|
|||||||
REQUIRES: zlib
|
|
||||||
|
|
||||||
// dwarfdump-decompression-invalid-size.elf-x86-64 is prepared using following
|
|
||||||
// source code and invocation:
|
|
||||||
// test.cpp:
|
|
||||||
// int main() { return 0; }
|
|
||||||
//
|
|
||||||
// gcc test.cpp -o out -g -Wl,--compress-debug-sections,zlib
|
|
||||||
//
|
|
||||||
// After that result object was modified manually. Decompressed size of
|
|
||||||
// .debug_frame section was changed to 0xffffffffffffffff in compression
|
|
||||||
// header.
|
|
||||||
RUN: not llvm-dwarfdump %p/Inputs/dwarfdump-decompression-invalid-size.elf-x86-64 2>&1 | FileCheck %s
|
|
||||||
|
|
||||||
CHECK: decompression of '.debug_frame' failed: unable to allocate 18446744073709551615 bytes.
|
|
Loading…
Reference in New Issue
Block a user