ahupp / python-magic

A python wrapper for libmagic
Other
2.59k stars 280 forks source link

On AlmaLinux 8, corrupt .gz files no longer raise an exception #308

Closed tgs closed 10 months ago

tgs commented 10 months ago

In my application, we use Magic(uncompress=True) to detect corrupted gzip files. On CentOS 7, this code behaves as expected, raising a MagicException:

from magic import Magic
m = Magic(mime=True, mime_encoding=True, uncompress=True)
m.from_file('corrupted.gz')

-> magic.MagicException: b'zlib: invalid stored block lengthsapplication/x-empty compressed-encoding=application/x-gzip; charset=binary; charset=binary'

However, on AlmaLinux 8, it seems to just return a string holding an error message: 'zlib ERROR: invalid stored block lengths compressed-encoding=application/x-gzip; charset=binary'

Both are running python-magic 0.4.27

Versions of libmagic - let me know if this isn't enough detail CentOS7 has file-libs-5.11-37.el7.x86_64 - works Alma8 has file-libs-5.33-24.el8.x86_64 - doesn't work

Thanks for a super useful library, we'd appreciate any help you can give!

ahupp commented 10 months ago

Thanks for the report! The library is supposed to return null for an error here, and then we fetch the message with magic_error.

This sounds like a regression in libmagic, could you file it here?

https://bugs.astron.com/my_view_page.php

tgs commented 10 months ago

Huh, looking at it from their perspective, they probably consider it a feature...

 The magic_file() function returns a textual description of the
 contents of the filename argument, or NULL if an error occurred.
 If the filename is NULL, then stdin is used.

"if an error occurred" - not "if the file is erroneous"

Thank you for taking a look!