mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
conversion: Add sanity check for page count
Add a sanity check at the end of the conversion from doc to pixels, to ensure that the resulting document will have the same number of pages as the original one. Refs #560
This commit is contained in:
parent
b4e5cf5be7
commit
ccf4132ea0
2 changed files with 18 additions and 5 deletions
|
@ -349,16 +349,22 @@ class DocumentToPixels(DangerzoneConverter):
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.update_progress("Converted document to pixels")
|
final_files = (
|
||||||
|
|
||||||
# Move converted files into /tmp/dangerzone
|
|
||||||
for filename in (
|
|
||||||
glob.glob("/tmp/page-*.rgb")
|
glob.glob("/tmp/page-*.rgb")
|
||||||
+ glob.glob("/tmp/page-*.width")
|
+ glob.glob("/tmp/page-*.width")
|
||||||
+ glob.glob("/tmp/page-*.height")
|
+ glob.glob("/tmp/page-*.height")
|
||||||
):
|
)
|
||||||
|
|
||||||
|
# XXX: Sanity check to avoid situations like #560.
|
||||||
|
if not running_on_qubes() and len(final_files) != 3 * num_pages:
|
||||||
|
raise errors.PageCountMismatch()
|
||||||
|
|
||||||
|
# Move converted files into /tmp/dangerzone
|
||||||
|
for filename in final_files:
|
||||||
shutil.move(filename, "/tmp/dangerzone")
|
shutil.move(filename, "/tmp/dangerzone")
|
||||||
|
|
||||||
|
self.update_progress("Converted document to pixels")
|
||||||
|
|
||||||
async def install_libreoffice_ext(self, libreoffice_ext: str) -> None:
|
async def install_libreoffice_ext(self, libreoffice_ext: str) -> None:
|
||||||
self.update_progress(f"Installing LibreOffice extension '{libreoffice_ext}'")
|
self.update_progress(f"Installing LibreOffice extension '{libreoffice_ext}'")
|
||||||
unzip_args = [
|
unzip_args = [
|
||||||
|
|
|
@ -82,6 +82,13 @@ class MaxPageHeightException(PagesException):
|
||||||
error_message = f"A page exceeded the maximum height."
|
error_message = f"A page exceeded the maximum height."
|
||||||
|
|
||||||
|
|
||||||
|
class PageCountMismatch(PagesException):
|
||||||
|
error_code = ERROR_SHIFT + 46
|
||||||
|
error_message = (
|
||||||
|
"The final document does not have the same page count as the original one"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PDFtoPPMException(ConversionException):
|
class PDFtoPPMException(ConversionException):
|
||||||
error_code = ERROR_SHIFT + 50
|
error_code = ERROR_SHIFT + 50
|
||||||
error_message = "Error converting PDF to Pixels (pdftoppm)"
|
error_message = "Error converting PDF to Pixels (pdftoppm)"
|
||||||
|
|
Loading…
Reference in a new issue