Skip to content

Commit 350328a

Browse files
committed
Address user feedback to check for increasing sections sizes.
We now return an error if a section file offset exceeds 4GB and the sections are not ordered in the mach-o file. If sections are not ordered, we can't assume the section file offset overflows make sense to apply to other sections, but we can if they are ordered.
1 parent 159cfd7 commit 350328a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,14 +1996,20 @@ MachOObjectFile::getSectionContents(DataRefImpl Sec) const {
19961996
// 4GB. MachO::section_64 objects only have 32 bit file offsets to the
19971997
// section contents and can overflow in dSYM files. We can track this and
19981998
// adjust the section offset to be 64 bit safe.
1999+
// Assumes the sections are ordered.
2000+
uint64_t PrevTrueOffset = 0;
19992001
uint64_t SectOffsetAdjust = 0;
20002002
for (uint32_t SectIdx=0; SectIdx<Sec.d.a; ++SectIdx) {
20012003
MachO::section_64 CurrSect =
20022004
getStruct<MachO::section_64>(*this, Sections[SectIdx]);
2005+
uint64_t CurrTrueOffset = (uint64_t)CurrSect.offset + SectOffsetAdjust;
2006+
if ((SectOffsetAdjust > 0) && (PrevTrueOffset > CurrTrueOffset))
2007+
return malformedError("section data exceeds 4GB and are not ordered");
20032008
const uint64_t EndSectFileOffset =
20042009
(uint64_t)CurrSect.offset + CurrSect.size;
2005-
if (EndSectFileOffset >= UINT32_MAX)
2010+
if (EndSectFileOffset > UINT32_MAX)
20062011
SectOffsetAdjust += EndSectFileOffset & 0xFFFFFFFF00000000ull;
2012+
PrevTrueOffset = CurrTrueOffset;
20072013
}
20082014
Offset += SectOffsetAdjust;
20092015
} else {

0 commit comments

Comments
 (0)