From bc83341d2a21551736b62d80974d6eba6bc75420 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Thu, 3 Aug 2023 17:35:47 +0300 Subject: [PATCH] conversion: Detect when LibreOffice silently fails Sometimes, LibreOffice returns with status code 0, but in reality, it fails. It doesn't create a file, and Dangerzone does not detect this. What happens next is that it fails in the next command, and throws an unrelated error. Detect that LibreOffice fails, by checking if the output file exists, after the PDF conversion. --- dangerzone/conversion/doc_to_pixels.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dangerzone/conversion/doc_to_pixels.py b/dangerzone/conversion/doc_to_pixels.py index e3703de..2f8eb55 100644 --- a/dangerzone/conversion/doc_to_pixels.py +++ b/dangerzone/conversion/doc_to_pixels.py @@ -185,6 +185,12 @@ class DocumentToPixels(DangerzoneConverter): timeout=timeout, ) pdf_filename = "/tmp/input_file.pdf" + # XXX: Sometimes, LibreOffice can fail with status code 0. So, we need to + # always check if the file exists. See: + # + # https://github.com/freedomofpress/dangerzone/issues/494 + if not os.path.exists(pdf_filename): + raise ValueError("Conversion to PDF with LibreOffice failed") elif conversion["type"] == "convert": self.update_progress("Converting to PDF using GraphicsMagick") args = [