From a453c890a0f0da287cc3172a5359593eb25dfc10 Mon Sep 17 00:00:00 2001 From: Moon Sungjoon Date: Thu, 20 Jul 2023 05:48:58 +0900 Subject: [PATCH] Fix dynamic loading of LibreOffice extensions HWPX MIME type is recognized as 'application/zip' with current version of file command (file-5.44). It will be recognized as 'application/hwp+zip' when new version of file is released. For a temporary fix, when MIME type of file is 'application/zip', check the file type again (without the MIME option). And then check if it's 'Zip data (MIME type "application/hwp+zip"?)' or not. --- dangerzone/conversion/doc_to_pixels.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index 10e73ee..fd50f1c 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -78,10 +78,6 @@ class DocumentToPixels(DangerzoneConverter): "type": "libreoffice", }, # .hwp - "application/vnd.hancom.hwp": { - "type": "libreoffice", - "libreoffice_ext": "h2orestart.oxt", - }, "application/haansofthwp": { "type": "libreoffice", "libreoffice_ext": "h2orestart.oxt", @@ -91,16 +87,9 @@ class DocumentToPixels(DangerzoneConverter): "libreoffice_ext": "h2orestart.oxt", }, # .hwpx - "application/vnd.hancom.hwpx": { - "type": "libreoffice", - "libreoffice_ext": "h2orestart.oxt", - }, - "application/haansofthwpx": { - "type": "libreoffice", - "libreoffice_ext": "h2orestart.oxt", - }, "application/hwp+zip": { "type": "libreoffice", + "libreoffice_ext": "h2orestart.oxt", }, # At least .odt, .docx, .odg, .odp, .ods, and .pptx "application/zip": { @@ -136,6 +125,13 @@ class DocumentToPixels(DangerzoneConverter): if mime_type not in conversions: raise ValueError("The document format is not supported") + # Temporary fix for the HWPX format + if mime_type == "application/zip": + file_type = magic.from_file("/tmp/input_file") + hwpx_file_type = 'Zip data (MIME type "application/hwp+zip"?)' + if file_type == hwpx_file_type: + mime_type = "application/hwp+zip" + # Get file size (in MiB) size = os.path.getsize("/tmp/input_file") / 1024**2