aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFObjectFile.cpp
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2022-06-08 23:55:45 +0300
committerMartin Storsjö <martin@martin.st>2022-06-15 16:51:20 +0300
commitb209b9e11c265e52f5897b2e014aa6933eb26703 (patch)
tree2e0c118e27f58a02d92b47e377058dc8ffe36135 /llvm/lib/Object/COFFObjectFile.cpp
parentc60c13f7eb7157de1986c0da955d8ba856b65e07 (diff)
downloadllvm-b209b9e11c265e52f5897b2e014aa6933eb26703.zip
llvm-b209b9e11c265e52f5897b2e014aa6933eb26703.tar.gz
llvm-b209b9e11c265e52f5897b2e014aa6933eb26703.tar.bz2
[COFF] Don't reject executables with data directories pointing outside of provided data
Before bb94611d6545c2c5271f5bb01de1aa4228a37250, we didn't check that the sections in the COFF executable actually contained enough raw data, when looking up what section contains tables pointed to by the data directories. That commit added checking, to avoid setting a pointer that points out of bounds - by rejecting such executables. It turns out that some binaries (e.g.g a "helper.exe" provided by NSIS) contains a base relocation table data directory that points into the wrong section. It points inside the virtual address space allocated for that section, but the section contains much less raw data, and the table points outside of the provided raw data. No longer reject such binaries (to let tools operate on them and inspect them), but don't set the table pointers (so that when printing e.g. base relocations, we don't print anything). This should fix the regression pointed out in https://reviews.llvm.org/D126898#3565834. Differential Revision: https://reviews.llvm.org/D127345
Diffstat (limited to 'llvm/lib/Object/COFFObjectFile.cpp')
-rw-r--r--llvm/lib/Object/COFFObjectFile.cpp14
1 files changed, 4 insertions, 10 deletions
diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp
index e5013d77..ee5411d 100644
--- a/llvm/lib/Object/COFFObjectFile.cpp
+++ b/llvm/lib/Object/COFFObjectFile.cpp
@@ -483,18 +483,12 @@ Error COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res,
// fail, otherwise it will be impossible to use this object as debug info
// in LLDB. Return SectionStrippedError here so that
// COFFObjectFile::initialize can ignore the error.
- if (Section->SizeOfRawData == 0)
- return make_error<SectionStrippedError>();
+ // Somewhat common binaries may have RVAs pointing outside of the
+ // provided raw data. Instead of rejecting the binaries, just
+ // treat the section as stripped for these purposes.
if (Section->SizeOfRawData < Section->VirtualSize &&
Addr >= SectionStart + Section->SizeOfRawData) {
- if (ErrorContext)
- return createStringError(object_error::parse_failed,
- "RVA 0x%" PRIx32
- " for %s found but data is incomplete",
- Addr, ErrorContext);
- return createStringError(
- object_error::parse_failed,
- "RVA 0x%" PRIx32 " found but data is incomplete", Addr);
+ return make_error<SectionStrippedError>();
}
uint32_t Offset = Addr - SectionStart;
Res = reinterpret_cast<uintptr_t>(base()) + Section->PointerToRawData +