pythondjangopython-magiclibmagic

MagicException: b"File 5.45 supports only version 18 magic files. `/path/to/my/magic.mgc' is version 14"


I've recently taken over the Django GraphQL backend for the app I work on. I'm primarily an iOS Dev and have some knowledge of Python and only minimal experience learning Django, so this has been quite the trial by fire.

After writing what I beleive to be the changes to the model and adding a query for a new feature we're adding, I tried to run makemigrations and I'm getting the following error:

magic.MagicException: b"File 5.45 supports only version 18 magic files. `app_common/misc/magic.mgc' is version 14"

This is preceded by the stack trace (I can provide if needed) and a couple hundred lines of:

app_common/misc/magic.mgc, 2653: Warning: offset `.' invalid

I've tried searching and most recommendations are to update libmagic or python-magic. While my current version is showing 14 because I thought maybe I had made some mistake in the setup process for the project and deleted and recloned it, when I previously updated those and recompiled the magic file, I only managed to get it up to version 16 with the most up to date packages.

Additionally when I check the version of file with file -v, it shows me that it's version 5.41.

I am on a mac and an article I saw made it seem that file was built in to the os. So I did update my os to the most recent (Sonoma 14.0) thinking that might update it. That did not update the file -v result and it's still at 5.41 and the magic.mgc file created was still only 16.

So, it seems that either I need to update the File version on my computer, or use the 5.45 version to compile the magic file (which I couldn't figure out how to do), or figure out how to tell it to only expect version 14 (or even 16 would be ok), but I'm not sure exactly how to do that either. I suspect that I need to install some previous version of libmagic to get this last one done, but I haven't been able to find the version history for that or figure out how to install a lower version of libmagic for this purpose.

I am happy to provide any snippets of code that would help figure this out, but unfortunately this is entirely new to me and I'm not even sure what would help. I would greatly appreciate any help figuring any way to resolve this.


Solution

  • Just to update for anyone else running into this problem... The main problem was that the system file was not updating when I did brew install so when I ran file -C -m ..... it was using the systems version 5.41 rather than the 5.45 that I had installed. The solution to this was to use the full path of the homebrew install as such:

    /opt/homebrew/Cellar/file-formula/5.45/bin/file -C -m magic.mgc myapp/misc/magic.mgc

    This finally created the version 18 magic.mgc file. Hope this helps someone else in the future!