-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle fileoff out of file boundary in load segment commandj when parsing Mach-O #172
Conversation
Handle gracefully the fileoff in load segment command being outside of file boundary as it can occur in valid Mach-O files
I prefer a minimal fix of only ignoring |
Would it be preferable to make |
It's not a new failure mode. It's an existing failure mode that most (all?) consumers want to ignore because files like this exist in practice, and in the absence of a spec that says otherwise, I don't see any benefit to treating this as a failure.
I don't think it does that, unless you're proposing to return an error if If we're considering interface changes then my preference would be to split the parsing:
But I think anything like that should be a separate PR. We should at least do an initial minimal fix of ignoring |
I think @philipc suggestion is way forward here; @raindev can you force push that change to your branch, and we can merge? 0 size data entries should have empty data; this might even be a bug in scroll attempting to pread a 0 size data array. Need to check. @willglynn I like your suggestion too, but for now I think we should just parse out the 0 array, and in future if enough robustness is required, move the result array into the field as you suggested, but we can hold off on that for now :) |
On the note of that object file, @raindev where did you get it? It's weird in a few other ways, e.g.:
why is load command 1 |
Relying on filesize being zero sounds like a better approach to me as well, I've added a commit with the change. |
@m4b Looks like it is |
Ok new goblin is published, |
Thank you for getting it in quickly! |
Thank you for the PR and identifying the issue ! |
When parsing BoringSSL's object files built on macOS I had goblin failing on some with
bad offset x
where x is outside of file boundary (pointing at the byte right after the end of the object). It might be a toolchain bug but since such binaries exist it would be useful if goblin could handle them. objdump does not fail to parse those files nor Go's Mach-O parser does. The easiest way to reproduce the problem is to build BoringSSL and run bingrep on cpu-aarch64-fuchsia.c.o (a copy in my Dropbox to save time) or fuchsia.c.o.I've intentionally only checked
fileoff
being outside of file boundary and notfileoff + filesize
to not hide problems when an object file is obviously malformed.