Repository navigation
from_buffer() issue with file-5.47 #362
Description
Activity
I can confirm this issue, just tried bumping to file-5.47 in #294 and the smoke test starts failing:
Successfully installed python-magic-0.4.28 + /bin/sh -c 'python -c "import magic; assert magic.Magic(mime=True).from_buffer(b'"'"'\x00\x00\x00\x1cftypiso5\x00\x00\x00\x01isomiso5hlsf\x00\x00'"'"') == '"'"'video/mp4'"'"'"' Traceback (most recent call last): File "<string>", line 1, in <module> AssertionErrorSounds like an upstream issue because this library is just a CDLL wrapper.
Reacted by RafayAK- added a commit that references this issue
on Mar 21, 2026 Hiya,
For anyone stumbling here, a similar problem was reported upstream here (requires creating an account).
Date Submitted: 2026-03-04 12:58
Last Update: 2026-04-01 08:54They seem to be on the right track. I spent some time digging tonight, I had identified a commit that messed with offset calculations in
file_buffer(). I intended to report it, but I found that issue, and based on the latest comments from today, they found the same commit and code paths I was looking at.In the meantime:
- Using
magic.from_file()ormagic.from_descriptor()works fine. - If you really want to use buffers (e.g. to avoid reading huge files), save the buffer to a temporary file and use
magic.from_file()on that. - Or pin your file package ≤ 5.46, until further news.
UPDATE: The bug is reported as patched by one of the maintainers, as of 2026-04-12 22:15 (UTC). All we need now is to wait for a 5.48 release. Which unfortunately might take a while: 5.47 landed Feb 26, 2026, 5.46 landed Nov 27, 2024. Let's hope we won't have to wait 1 more year. 😅
Reacted by Wesley Moore, ddelange, pfcodes and RafayAK- Using
- added a commit that references this issue
on Apr 8, 2026 Did anyone manage to figure out what upstream commit fixed the issue? I didn't find a clear candidate here:
I'd like to patch it for my distribution...
Did anyone manage to figure out what upstream commit fixed the issue? I didn't find a clear candidate here:
* https://bugs.astron.com/view.php?id=725I'd like to patch it for my distribution...
Here you go:
file/file@c546057Reacted by Doron BeharJust faced this issue, for somereason
audio/oggis getting picked up asapplication/octet-streampython -u - <<'PY' import magic p='/Path/To/Audio-Notes/Q1.ogg' m=magic.Magic(mime=True) print('from_file', m.from_file(p)) with open(p,'rb') as f: b=f.read(8192) print('from_buffer_2048', m.from_buffer(b[:2048])) print('from_buffer_8192', m.from_buffer(b)) PY from_file audio/ogg from_buffer_2048 application/octet-stream from_buffer_8192 application/octet-stream
Using archlinux, with python-magic 0.4.27, there seems to be an issue with file-5.47-1 and python-magic when using
from_bufferafter downgrading to file-5.46-5 everything works