Offer hint to user to use --max-image-mpixels after decompression bob error

Closes #801
This commit is contained in:
James R. Barlow
2021-10-06 00:19:11 -07:00
parent 7bdd1828a9
commit 78f391536b
2 changed files with 12 additions and 6 deletions
+7
View File
@@ -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
+5 -6
View File
@@ -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'
)