Skip to content

Commit

Permalink
[Object] Ensure header size not to underflow in OffloadBinary::create
Browse files Browse the repository at this point in the history
Prevent potential integer underflows when header size is not valid.

Fixes: #86280.
  • Loading branch information
antoniofrighetto committed Mar 22, 2024
1 parent 9c0a065 commit 6f44bb7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion llvm/lib/Object/OffloadBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

1 comment on commit 6f44bb7

@arichardson
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test? Ideally every error case has a test

Please sign in to comment.