Skip to content
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

Incompatible magic.mgc version on OSX #59

Open
jorimvanhove opened this issue Jan 9, 2025 · 3 comments
Open

Incompatible magic.mgc version on OSX #59

jorimvanhove opened this issue Jan 9, 2025 · 3 comments

Comments

@jorimvanhove
Copy link

Method call: MimeGuesser.GuessMimeType

Using v3.7.0, I get this error on macOS Sequoia 15.1.1 (M2 Pro)

HeyRed.Mime.MagicException: File 5.46 supports only version 20 magic files. '/{{project}}/bin/Debug/net8.0/runtimes/osx-arm64/native/magic.mgc' is version 19

v3.6.0 appears to work as expected.

@hey-red
Copy link
Owner

hey-red commented Jan 9, 2025

Do you try to cleanup/rebuild project? Or just clear our Debug directory?
I think this db remainded from previous version.

All magic.mgc files in "runtimes/*" should have same version, because it's same file from repo https://github.com/hey-red/Mime/blob/master/src/Mime/content/magic.mgc

@jorimvanhove
Copy link
Author

jorimvanhove commented Jan 14, 2025

The issue was encountered on first installation of the package, using v3.7.0. No previous version of the package was installed prior.

I created an MRE here https://github.com/jorimvanhove/heyred-mime-issue59

I can confirm that the /{{project}}/bin/Debug/net8.0/runtimes/osx-arm64/native/magic.mgc is exactly the same as the magic.mgc files in the other directories. Somehow the package appears to read a magic.mgc file from a different location on the system than the path that is reported in the exception. During debugging I wasn't able to pin-point the relevant path of the magic.mgc file being used in the constructor.
As in my production code, switching to v3.6.0 resolves the issue. Switching back to v3.7.0 makes the issue re-appear.

@jorimvanhove
Copy link
Author

Using the MRE https://github.com/jorimvanhove/heyred-mime-issue59, I was able to reproduce the same issue on osx-x64.

I decompiled the binaries that ship with Mime.
I suspect the issue is related to the following code in libmagic-1.dylib:

Image

The libmagic-1.dylib binary that ships with v3.6.0 checks for the number 18:

Image

Examining the linux-x64 binaries it appears for File 5.45 the required magic file version is 18, and 19 for 5.46

Image Image

I compared the magic.mgc file that ships with the homebrew libmagic package, and it differs from the magic.mgc file shipped with Mime.

Setting the MimeGuesser.MagicFilePath to the homebrew magic.mgc file all is good, and the test is green.
MimeGuesser.MagicFilePath = "/opt/homebrew/Cellar/libmagic/5.46/share/misc/magic.mgc";

https://formulae.brew.sh/formula/libmagic#default

It appears likely that for macOS (x64 & arm64) it is necessary to ship the magic.mgc file that comes with the homebrew package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants