python-magic icon indicating copy to clipboard operation
python-magic copied to clipboard

With uncompress=True, crashes parent process (crash, not exception)

Open merutak opened this issue 6 years ago • 4 comments

I've found that the combination of from_buffer and uncompress=True can crash the library. I suspect, but am unsure, that this stems from wrong usage of file_buffer.

My system is Ubuntu 16.04, also experienced this with Ubuntu 12.04; Python is 2.7.

Reproduce (edited re @ahupp ): You need a zipped file, I use a 'docx' -- pretty much any docx would do. Then run: magic.Magic(mime=True, uncompress=True).from_buffer(open("filename.docx").read()) This crashes my Python.

merutak avatar Dec 07 '19 20:12 merutak

I'm not able to reproduce this:

>>> import magic
>>> magic.Magic(uncompress=True, mime=True).from_file('test.docx')
'text/xml'
>>> magic.Magic(uncompress=True, mime=True).from_buffer(open('test.docx').read(1024))
'text/xml'

It wasn't clear if you meant from_buffer or from_file, the description says the former but the example says latter. This is with libmagic 5.35 and python-magic 0.4.15.

16.04 has libmagic 5.25, possibly there's a bugfix between .25 and .35.

ahupp avatar Dec 07 '19 22:12 ahupp

I can repro with 5.25, but not 5.30.

ahupp avatar Dec 11 '19 00:12 ahupp

And it only happens with from_buffer, not from_file.

ahupp avatar Dec 11 '19 00:12 ahupp

It happens with the magic distributions python bindings as well. I've reported the bug to them:

https://bugs.astron.com/view.php?id=125

ahupp avatar Dec 11 '19 01:12 ahupp

libmagic bug, closing.

ahupp avatar Aug 25 '23 18:08 ahupp