Closed paul-nameless closed 2 years ago
This is an error from inside libmagic, rather than the python-magic wrapper. Does this only happen on some files? Does something like:
magic.from_buffer(open(fname).read(1024))
give the same result?
>>> magic.from_buffer(open("078a38e0bb7962fb145f75fbd5099321162c108ecb66123c88032f1c620aad72").read(1024))
Traceback (most recent call last):
File "<input>", line 1, in <module>
magic.from_buffer(open("078a38e0bb7962fb145f75fbd5099321162c108ecb66123c88032f1c620aad72").read(1024))
File "/Users/paul/Documents/job/venv/bin/../lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 25: invalid continuation byte
>>> magic.from_buffer(open("078a38e0bb7962fb145f75fbd5099321162c108ecb66123c88032f1c620aad72", 'rb').read(1024))
'ELF 64-bit LSB executable, x86-64, version 1 (SYSV)'
This is what I got. Is it python level problem or libmagic one? Should I investigate further it there? Is it valid to use magic library like this?
magic.from_buffer(open("078a38e0bb7962fb145f75fbd5099321162c108ecb66123c88032f1c620aad72", 'rb').read(1024))
Its a problem inside libmagic, which unfortunately makes it a bit harder to track down. It looks like there's some elf-specific logic that can trigger this read error, possibly here:
Is the file truncated in some weird way? If you pass the entire file to from_buffer do you get the same result?
I got exception with some files:
> file 078a38e0bb7962fb145f75fbd5099321162c108ecb66123c88032f1c620aad72