ghostscript/PDF-interpreter-swallow-errors-reading-ICC-profiles-and-continue.patch
2020-09-03 15:54:45 +08:00

48 lines
1.8 KiB
Diff

From a45d7217c8c1578475ee9204d1f4ad46520f44d1 Mon Sep 17 00:00:00 2001
From: Ken Sharp <ken.sharp@artifex.com>
Date: Sat, 21 Mar 2020 10:00:42 +0000
Subject: [PATCH] PDF interpreter - swallow errors reading ICC profiles and
continue
Bug #702240 "Invalid ICC profile aborts PDF ineterpretation"
The file contains an ICCbased space which references an embedded ICC
profile, which is Flate compressed. The compressed stream has been
corrupted and cannot be decompressed.
This causes the colour space code to throw an ioerror and terminate
interpretation, Acrobat (as usual) doesn't even give a warning.
This commit checks for an error creating the ReusableStreamDecode and
if it fails sets the Data Source in the stream dictionary to null. We
will later use the /N value in the stream dictionary to set a reasonable
fallback space (in this case CMYK).
---
Resource/Init/pdf_draw.ps | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
index 1deb052..9d818de 100644
--- a/Resource/Init/pdf_draw.ps
+++ b/Resource/Init/pdf_draw.ps
@@ -874,7 +874,15 @@ currentdict /csncompdict undef
dup dup 1 oget
mark exch { oforce } forall .dicttomark
dup dup //true resolvestream
- /ReusableStreamDecode filter /DataSource exch put
+ {
+ /ReusableStreamDecode filter
+ } stopped
+ {
+ pop null
+% ( **** Error: Failed to read ICC profile for an ICCBased colour space.\n) pdfformaterror
+% ( Falling back to a colour space determined by the /N value.\n) pdfformaterror
+ }if
+ /DataSource exch put
dup /.hash 0 put % placeholder for use by seticc icc_profile_cache key
% Check that the number of components (/N) defined in the ICCBased
% dictionry matches the actual profile. Bug #696120
--
1.8.3.1