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.
This commit is contained in:
Alex Pyrgiotis 2023-08-03 17:35:47 +03:00 committed by deeplow
parent 6736fb0153
commit bc83341d2a
No known key found for this signature in database
GPG key ID: 577982871529A52A

View file

@ -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 = [