Add test case for corrupt ICC profiles

This commit is contained in:
James R. Barlow 2022-05-26 00:41:19 -07:00
parent e7a44ba87a
commit 6c427f82ea
2 changed files with 23 additions and 1 deletions

View File

@ -361,7 +361,7 @@ class ImageInfo:
self._comp = 3
except UnsupportedImageTypeError as ex:
self._comp = None
logger.warn(
logger.warning(
f"An image with a corrupt or unreadable ICC profile was found. "
f"The output PDF may not match the input PDF visually: {ex}. {self}"
)

View File

@ -922,3 +922,25 @@ def test_outputtype_none(resources, outtxt):
'tests/plugins/tesseract_noop.py',
)
assert p.returncode == ExitCode.ok
@pytest.fixture
def graph_bad_icc(resources, outdir):
synth_input_file = outdir / 'graph-bad-icc.pdf'
with pikepdf.open(resources / 'graph.pdf') as pdf:
icc = pdf.make_stream(
b'invalid icc profile', N=3, Alternate=pikepdf.Name.DeviceRGB
)
pdf.pages[0].Resources.XObject['/Im0'].ColorSpace = pikepdf.Array(
[pikepdf.Name.ICCBased, icc]
)
pdf.save(synth_input_file)
yield synth_input_file
def test_corrupt_icc(graph_bad_icc, outpdf, caplog):
result = run_ocrmypdf_api(graph_bad_icc, outpdf)
assert result == ExitCode.ok
assert any(
'corrupt or unreadable ICC profile' in rec.message for rec in caplog.records
)