Skip to content

Commit 5d99a97

Browse files
nikicllvmbot
authored andcommitted
[MachO] Improve bounds check (llvm#141083)
The current check may fail if the addition overflows. I've observed failures of macho-invalid.test on 32-bit due to this. Instead, compare against the remaining bytes until the end of the object. (cherry picked from commit 3f29acb)
1 parent aa804fd commit 5d99a97

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ static Expected<MachOObjectFile::LoadCommandInfo>
192192
getLoadCommandInfo(const MachOObjectFile &Obj, const char *Ptr,
193193
uint32_t LoadCommandIndex) {
194194
if (auto CmdOrErr = getStructOrErr<MachO::load_command>(Obj, Ptr)) {
195-
if (CmdOrErr->cmdsize + Ptr > Obj.getData().end())
195+
assert(Ptr <= Obj.getData().end() && "Start must be before end");
196+
if (CmdOrErr->cmdsize > (uintptr_t)(Obj.getData().end() - Ptr))
196197
return malformedError("load command " + Twine(LoadCommandIndex) +
197198
" extends past end of file");
198199
if (CmdOrErr->cmdsize < 8)

0 commit comments

Comments
 (0)