mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 02:12:36 +02:00
Support multiple Python libraries for libmagic
It seems that there are at least two Python libraries with libmagic support: * PyPI: python-magic (https://pypi.org/project/python-magic/) On Fedora it's `python3-magic` * PyPI: filemagic (https://pypi.org/project/filemagic/) On Fedora it's `python3-file-magic` The first package corresponds to the `py3-magic` package on Alpine Linux, and it's the one we install in the container. The second package uses a different API, and it's the only one we can use on Qubes. To make matters worse, we: * Can't install the first package on Fedora, because it installs the second under the hood: https://bugzilla.redhat.com/show_bug.cgi?id=1899279 * Can't install the second package on Alpine Linux (untested), due to Musl being used instead of libC: https://stackoverflow.com/a/53936722 Ultimately, we need to support both, by trying the first API, and on failure using the other API.
This commit is contained in:
parent
9410da762c
commit
cfdaec23c5
1 changed files with 5 additions and 2 deletions
|
@ -101,8 +101,11 @@ class DocumentToPixels(DangerzoneConverter):
|
|||
}
|
||||
|
||||
# Detect MIME type
|
||||
try:
|
||||
mime = magic.Magic(mime=True)
|
||||
mime_type = mime.from_file("/tmp/input_file")
|
||||
except TypeError:
|
||||
mime_type = magic.detect_from_filename("/tmp/input_file").mime_type
|
||||
|
||||
# Validate MIME type
|
||||
if mime_type not in conversions:
|
||||
|
|
Loading…
Reference in a new issue