From 78f391536b03c2c6b221b73cbdfd4d1ec9202224 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 6 Oct 2021 00:19:11 -0700 Subject: [PATCH] Offer hint to user to use --max-image-mpixels after decompression bob error Closes #801 --- src/ocrmypdf/_sync.py | 7 +++++++ tests/test_main.py | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index 31693f9e..ea76dabb 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -414,6 +414,13 @@ def run_pipeline(options, *, plugin_manager, api=False): else: log.error(type(e).__name__) return e.exit_code + except (PIL.Image.DecompressionBombError if not api else NeverRaise) as e: + log.exception( + "A decompression bomb error was encountered while executing the " + "pipeline. Use the argument --max-image-mpixels to raise the maximum " + "image pixel limit." + ) + return ExitCode.other_error except (Exception if not api else NeverRaise): # pylint: disable=broad-except log.exception("An exception occurred while executing the pipeline") return ExitCode.other_error diff --git a/tests/test_main.py b/tests/test_main.py index 92e1c97f..5c326b79 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -745,14 +745,13 @@ def test_pdfa_n(pdfa_level, resources, outpdf): assert pdfa_info['conformance'] == f'PDF/A-{pdfa_level}B' -@pytest.mark.skipif( - PIL.__version__ < '5.0.0', reason="Pillow < 5.0.0 doesn't raise the exception" -) -@pytest.mark.slow -def test_decompression_bomb(resources, outpdf): +def test_decompression_bomb_error(resources, outpdf): p, _out, err = run_ocrmypdf(resources / 'hugemono.pdf', outpdf) - assert 'decompression bomb' in err + assert 'decompression bomb' in err and '--max-image-mpixels' in err + +@pytest.mark.slow +def test_decompression_bomb_succeeds(resources, outpdf): p, _out, err = run_ocrmypdf( resources / 'hugemono.pdf', outpdf, '--max-image-mpixels', '2000' )