diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -579,8 +579,11 @@ uintptr_t IntPtr = 0; if (Error E = getRvaPtr(ImportTableRva, IntPtr, "import table")) return E; - if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) - return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { + consumeError(std::move(E)); + return Error::success(); + } + ImportDirectory = reinterpret_cast< const coff_import_directory_table_entry *>(IntPtr); return Error::success(); @@ -602,6 +605,11 @@ uintptr_t IntPtr = 0; if (Error E = getRvaPtr(RVA, IntPtr, "delay import table")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { // ! + consumeError(std::move(E)); + return Error::success(); + } + DelayImportDirectory = reinterpret_cast< const delay_import_directory_table_entry *>(IntPtr); return Error::success(); @@ -623,6 +631,11 @@ uintptr_t IntPtr = 0; if (Error E = getRvaPtr(ExportTableRva, IntPtr, "export table")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { // ! + consumeError(std::move(E)); + return Error::success(); + } + ExportDirectory = reinterpret_cast(IntPtr); return Error::success(); @@ -640,6 +653,11 @@ if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr, "base reloc table")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { // ! + consumeError(std::move(E)); + return Error::success(); + } + BaseRelocHeader = reinterpret_cast( IntPtr); BaseRelocEnd = reinterpret_cast( @@ -668,6 +686,11 @@ if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr, "debug directory")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { // ! + consumeError(std::move(E)); + return Error::success(); + } + DebugDirectoryBegin = reinterpret_cast(IntPtr); DebugDirectoryEnd = reinterpret_cast( IntPtr + DataEntry->Size); @@ -700,6 +723,10 @@ if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr, "TLS directory")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { + consumeError(std::move(E)); + return Error::success(); + } if (is64()) TLSDirectory64 = reinterpret_cast(IntPtr); @@ -722,6 +749,10 @@ if (Error E = getRvaPtr(DataEntry->RelativeVirtualAddress, IntPtr, "load config table")) return E; + if (Error E = checkOffset(Data, IntPtr, DataEntry->Size)) { // ! + consumeError(std::move(E)); + return Error::success(); + } LoadConfig = (const void *)IntPtr; return Error::success();