Skip to content

Package fetch: add executable detection for Mach-O file headers #21555

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

Merged
merged 2 commits into from
Jan 21, 2025

Conversation

fabioarnold
Copy link
Contributor

@fabioarnold fabioarnold commented Sep 30, 2024

When trying to execute a binary fetched from a package I ran into this issue: #21044:

the expected behavior from the package manager is to ignore permissions from the zip file and set the execute bit based on ELF header and shebang line alone (see #17463)

Since this has been implemented for ELF already this change adds support for Mach-O.

@owenbrooks
Copy link

Great! Would be good to add std.macho.FAT_MAGIC and std.macho.FAT_MAGIC_64 to support multi-architecture binaries too.

@fabioarnold fabioarnold force-pushed the detect-macho-executable branch 2 times, most recently from 3ed9110 to 5ae4e6a Compare January 14, 2025 09:06
@fabioarnold fabioarnold force-pushed the detect-macho-executable branch from 5ae4e6a to 35b7d0c Compare January 14, 2025 09:10
@andrewrk andrewrk merged commit 97b97ae into ziglang:master Jan 21, 2025
10 checks passed
@andrewrk
Copy link
Member

andrewrk commented Jan 21, 2025

Great, thanks! This is breaking right? Since it will cause the hash to change on macOS for any executable files.

@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. labels Jan 21, 2025
@fabioarnold
Copy link
Contributor Author

Well thanks for reviewing and merging! :)

The way I understand the code is the package is fetched and extracted while files are created with the default mode (ModeMode.ignore in tar.zig), the hash is computed before ultimately the executable bits are set depending on the file type.

So this should be a non-breaking change. I checked this by deleting $HOME/.cache/zig and building my project each with a previous version of Zig and current master with this change. I didn't have to update my dependency's hash as was expected.

@andrewrk andrewrk removed the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants