This is an archive of the discontinued LLVM Phabricator instance.

[MachO] Prevent overflow on 32-bit platforms when calculating load command offsets
AcceptedPublic

Authored by awilfox on Nov 28 2022, 8:22 PM.

Details

Summary

This prevents overflow which can lead to llvm-objdump incorrectly accepting a malformed MachO file. This in turn caused the LLVM test suite to segfault on 32-bit Linux/musl platforms (since pointers are allocated in high memory on musl).

Fixes GitHub #56746.

Diff Detail

Event Timeline

awilfox created this revision.Nov 28 2022, 8:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 8:22 PM
awilfox requested review of this revision.Nov 28 2022, 8:22 PM

This was my solution to the related changeset D138830. It simplifies the logic a lot compared to that revision while still ensuring no overflow during calculation. I did not see the other overflows so perhaps it may be better to merge the two in some way. I'm not sure how to do that in Phabricator.

This was my solution to the related changeset D138830. It simplifies the logic a lot compared to that revision while still ensuring no overflow during calculation. I did not see the other overflows so perhaps it may be better to merge the two in some way. I'm not sure how to do that in Phabricator.

sorry, missed this revision/comment previously. I agree that this is simpler change, but I was hoping to fix the other potential overflows too . (Ack'ed that D138830. makes the code a bit ugly :\ .... open to other suggestions, tho)

MaskRay accepted this revision.Nov 30 2022, 8:05 PM

LGTM.

This revision is now accepted and ready to land.Nov 30 2022, 8:05 PM