[llvm] 6f44bb7 - [Object] Ensure header size not to underflow in `OffloadBinary::create`
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 07:46:28 PDT 2024
Author: Antonio Frighetto
Date: 2024-03-22T15:45:23+01:00
New Revision: 6f44bb7717897191be25aa01161831c67cdf5b84
URL: https://github.com/llvm/llvm-project/commit/6f44bb7717897191be25aa01161831c67cdf5b84
DIFF: https://github.com/llvm/llvm-project/commit/6f44bb7717897191be25aa01161831c67cdf5b84.diff
LOG: [Object] Ensure header size not to underflow in `OffloadBinary::create`
Prevent potential integer underflows when header size is not valid.
Fixes: https://github.com/llvm/llvm-project/issues/86280.
Added:
Modified:
llvm/lib/Object/OffloadBinary.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Object/OffloadBinary.cpp b/llvm/lib/Object/OffloadBinary.cpp
index 4ab6536dc90b52..6e9f8bed513c19 100644
--- a/llvm/lib/Object/OffloadBinary.cpp
+++ b/llvm/lib/Object/OffloadBinary.cpp
@@ -189,7 +189,10 @@ OffloadBinary::create(MemoryBufferRef Buf) {
return errorCodeToError(object_error::parse_failed);
if (TheHeader->Size > Buf.getBufferSize() ||
- TheHeader->EntryOffset > TheHeader->Size - sizeof(Entry) ||
+ TheHeader->Size < sizeof(Entry) || TheHeader->Size < sizeof(Header))
+ return errorCodeToError(object_error::unexpected_eof);
+
+ if (TheHeader->EntryOffset > TheHeader->Size - sizeof(Entry) ||
TheHeader->EntrySize > TheHeader->Size - sizeof(Header))
return errorCodeToError(object_error::unexpected_eof);
More information about the llvm-commits
mailing list