diff options
Diffstat (limited to 'include/llvm/Object/Binary.h')
-rw-r--r-- | include/llvm/Object/Binary.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/include/llvm/Object/Binary.h b/include/llvm/Object/Binary.h index 3f5a233c1ee1..5e93691d1fd2 100644 --- a/include/llvm/Object/Binary.h +++ b/include/llvm/Object/Binary.h @@ -15,6 +15,7 @@ #define LLVM_OBJECT_BINARY_H #include "llvm/ADT/Triple.h" +#include "llvm/Object/Error.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include <algorithm> @@ -43,6 +44,8 @@ protected: ID_COFFImportFile, ID_IR, // LLVM IR + ID_WinRes, // Windows resource (.res) file. + // Object and children. ID_StartObjects, ID_COFF, @@ -57,8 +60,6 @@ protected: ID_MachO64L, // MachO 64-bit, little endian ID_MachO64B, // MachO 64-bit, big endian - ID_WinRes, // Windows resource (.res) file. - ID_Wasm, ID_EndObjects @@ -143,6 +144,16 @@ public: return Triple::ELF; return Triple::UnknownObjectFormat; } + + static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, + const uint64_t Size) { + if (Addr + Size < Addr || Addr + Size < Size || + Addr + Size > uintptr_t(M.getBufferEnd()) || + Addr < uintptr_t(M.getBufferStart())) { + return object_error::unexpected_eof; + } + return std::error_code(); + } }; /// @brief Create a Binary from Source, autodetecting the file type. |