Bifurcate the readFile() API into ...
- readRawFile() which performs no checks, and
- readLinkableFile() which enforces minimum length of 20 bytes, same as ld64
There are no new tests because tweaks to existing tests are sufficient.
Differential D97610
[lld-macho] check minimum header length when opening linkable input files gkm on Feb 26 2021, 11:51 PM. Authored by
Details
Bifurcate the readFile() API into ...
There are no new tests because tweaks to existing tests are sufficient.
Diff Detail
Unit Tests
Event Timeline
Comment Actions a) I think this breaks --reproduce=repro.tar for -order_file since that previously called readFile() which added to the repro tar, but now readRawFile() doesn't. (Looks like -sectcreate has the same problem likely.) Comment Actions I believe avoiding ASAN errors, per https://reviews.llvm.org/D97600?id=326855#inline-915154 Comment Actions -sectcreate is subtle. It should be an opaque object immune to meddling, but as-is, if it happens to be MachO::FAT_MAGIC its arch component will be extracted. I am not going to fret about that until it proves troublesome.
The immediate motive was to fix an ASAN overflow when checking magic# of an empty buffer. My solution was an ill-conceived refactor with insufficient understanding. Apologies. This reverts the refactor and adds a modest one-line check that the file buffer is long-enough for a magic number: https://reviews.llvm.org/D97757 |
petition to keep this as addFile -- it's not like we have addRawFile, so the additional word seems unnecessary