Skip to content

Commit 16a0342

Browse files
Weitao-Sunclaude
andcommitted
Improve bounds checking and add file-backed validation in MachoView
Replace ad-hoc modulo guards with principled bounds derived from file structure where possible. The indirect symbol count is now clamped to the number of entries that physically fit between the table offset and end of file, accounting for the universal (fat) binary slice offset, using the OS-reported file size rather than any field from the binary. Export trie traversal uses the buffer length as its node visit limit, which prevents unbounded traversal including cyclic tries. Rebase and bind opcode entry counts are bounded by a single per-table total derived from the size of the Mach-O slice divided by its pointer size, scaled by a configurable multiplier (loader.macho.maxRebaseBindEntriesMultiplier, default 1.0), shared across all opcodes in one table via emitRebase/ emitBind helpers so every opcode that records an entry consumes the same budget. The endGuard underflow when the export trie buffer is empty, the symbols_offset wraparound in ProcessImports, and a missing catch(...) in MachoView::Init are also fixed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7c29ccd commit 16a0342

3 files changed

Lines changed: 152 additions & 115 deletions

File tree

view/macho/chained_fixups.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,9 @@ std::vector<ImportEntry> ChainedFixupProcessor::ProcessImports() const
313313

314314
auto header = ReadHeader(reader);
315315

316-
uint64_t symbolDataSize = m_fixupsSize - header.symbols_offset;
317-
if (!symbolDataSize) {
316+
if (header.symbols_offset >= m_fixupsSize)
318317
return imports;
319-
}
318+
uint64_t symbolDataSize = m_fixupsSize - header.symbols_offset;
320319
m_symbolData.resize(symbolDataSize);
321320
m_raw->Read(&m_symbolData[0], OffsetInFixups(header.symbols_offset), symbolDataSize);
322321

0 commit comments

Comments
 (0)