Blame SOURCES/ghostscript-fix-DSC-comment-parsing.patch

483aca
From f31702b38fba21153e26c3417c838618e7cfd16f Mon Sep 17 00:00:00 2001
483aca
From: Ken Sharp <ken.sharp@artifex.com>
483aca
Date: Fri, 21 Sep 2018 15:28:15 +0100
483aca
Subject: [PATCH] pdfwrite - fix DSC comment parsing
483aca
483aca
This may affect other DSC parsing utilities. For some reason double
483aca
comment (%%) marks are being interpreted 'sometimes' in gs_init.ps
483aca
as DSC comments. This only happens when reading the init files from disk
483aca
becuase the ROM file system strips comments.
483aca
483aca
Passing these to pdfwrite causes it to drop later DSC comments, such
483aca
as %%Title: and %%Creator: which meant the information wasn't being
483aca
embedded in the document information dictionary.
483aca
483aca
Fix by converting double %% to single % comments, document this in the
483aca
header of gs_init.ps.
483aca
---
483aca
 Resource/Init/gs_init.ps | 93 +++++++++++++++++++++-------------------
483aca
 1 file changed, 49 insertions(+), 44 deletions(-)
483aca
483aca
diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps
483aca
index ca20f12..d1278ea 100644
483aca
--- a/Resource/Init/gs_init.ps
483aca
+++ b/Resource/Init/gs_init.ps
483aca
@@ -20,6 +20,11 @@
483aca
 %	%% Replace <n> <file(s)>
483aca
 % indicate places where the next <n> lines should be replaced by
483aca
 % the contents of <file(s)>, when creating a single merged init file.
483aca
+%
483aca
+% For reasons not clear to me, some cases of %% are being treated as
483aca
+% DSC comments when (and only when) the resource files are disk based
483aca
+% This can kill DSC parsing for pdfwrite at least, so avoid using
483aca
+% double % comments in this file.
483aca
 
483aca
 % The interpreter can call out to PostScript code.  All procedures
483aca
 % called in this way, and no other procedures defined in these
483aca
@@ -136,12 +141,12 @@ currentdict /PDFNOCIDFALLBACK known /PDFNOCIDFALLBACK exch def
483aca
          ifelse
483aca
   .bind def
483aca
 
483aca
-%% This was a debugging switch removed in 9.22, no other software
483aca
-%% should have had any regard for it, and even if testing its value
483aca
-%% should have checked its existence first. However pstotext, an
483aca
-%% ancient and no longer maintained piece of softare, did check
483aca
-%% its value unconditionally. So we retain this key in the dictionary
483aca
-%% purely for backward compatibility.
483aca
+% This was a debugging switch removed in 9.22, no other software
483aca
+% should have had any regard for it, and even if testing its value
483aca
+% should have checked its existence first. However pstotext, an
483aca
+% ancient and no longer maintained piece of softare, did check
483aca
+% its value unconditionally. So we retain this key in the dictionary
483aca
+% purely for backward compatibility.
483aca
 /NOBIND false def
483aca
 
483aca
 currentdict /BATCH known   /BATCH exch def
483aca
@@ -2123,12 +2128,12 @@ currentdict /tempfilepaths undef
483aca
   //SAFETY /safe //true .forceput % overrides readonly
483aca
 } .bind executeonly odef
483aca
 
483aca
-%% This is only used during startup. Its required so that
483aca
-%% we can detect in setpagdevice that we are in fact in startup
483aca
-%% and allocate a *global* instead of local VM. We need it to be
483aca
-%% global to satisfy Display PostScript (see start of /setpagdevice
483aca
-%% in gs_setpd.ps)
483aca
-%%
483aca
+% This is only used during startup. Its required so that
483aca
+% we can detect in setpagdevice that we are in fact in startup
483aca
+% and allocate a *global* instead of local VM. We need it to be
483aca
+% global to satisfy Display PostScript (see start of /setpagdevice
483aca
+% in gs_setpd.ps)
483aca
+%
483aca
 /.locksafeglobal {
483aca
   .locksafe_userparams
483aca
   systemdict /getenv {pop //false} put
483aca
@@ -2157,8 +2162,8 @@ currentdict /tempfilepaths undef
483aca
   .locksafe
483aca
 } .bind executeonly odef
483aca
 
483aca
-%% See /.locksafeglobal above.
483aca
-%%
483aca
+% See /.locksafeglobal above.
483aca
+%
483aca
 /.setsafeglobal {
483aca
   SAFETY /safe get not {
483aca
     <<
483aca
@@ -2193,22 +2198,22 @@ SAFER { .setsafeglobal } if
483aca
 
483aca
 /UndefinePostScriptOperators {
483aca
 
483aca
-  %% This list is of Display PostScript operators. We believe that Display PostScript
483aca
-  %% was never fully implemented and the only known user, GNUStep, is no longer
483aca
-  %% using it. So lets remove it.
483aca
+  % This list is of Display PostScript operators. We believe that Display PostScript
483aca
+  % was never fully implemented and the only known user, GNUStep, is no longer
483aca
+  % using it. So lets remove it.
483aca
   [
483aca
   /condition /currentcontext /detach /.fork /join /.localfork /lock /monitor /notify
483aca
   /wait /yield /.currentscreenphase /.setscreenphase /.image2 /eoviewclip /initviewclip
483aca
   /viewclip /viewclippath /defineusername
483aca
-  %% NeXT DPS extensions
483aca
+  % NeXT DPS extensions
483aca
   /currentalpha /setalpha /.alphaimage /composite /compositerect /dissolve /sizeimagebox /.sizeimageparams
483aca
   ]
483aca
   {systemdict exch .forceundef} forall
483aca
 
483aca
-  %% This list is of operators which no longer appear to be used, and which we do not believe
483aca
-  %% to have any real use. For now we will undefine the operstors so they cannot easily be used
483aca
-  %% but can be easily restored (just delete the name from the list in the array). In future
483aca
-  %% we may remove the operator and the code implementation entirely.
483aca
+  % This list is of operators which no longer appear to be used, and which we do not believe
483aca
+  % to have any real use. For now we will undefine the operstors so they cannot easily be used
483aca
+  % but can be easily restored (just delete the name from the list in the array). In future
483aca
+  % we may remove the operator and the code implementation entirely.
483aca
   [
483aca
   /.bitadd /.charboxpath /.cond /.runandhide /.popdevicefilter
483aca
   /.execfile /.filenamesplit /.file_name_parent
483aca
@@ -2217,15 +2222,15 @@ SAFER { .setsafeglobal } if
483aca
   /.currentlimitclamp /.dotorientation /.setaccuratecurves /.setcurvejoin /.setdashadapt /.setdotorientation
483aca
   /.setlimitclamp /.currentscreenlevels /.dashpath /.pathbbox /.identeq /.identne /.tokenexec /.forgetsave /.pantonecallback
483aca
 
483aca
-  %% Used by our own test suite files
483aca
-  %%/.setdotlength % Bug687720.ps
483aca
+  % Used by our own test suite files
483aca
+  %/.setdotlength % Bug687720.ps
483aca
   ]
483aca
   {systemdict exch .forceundef} forall
483aca
 
483aca
-  %% This list of operators are used internally by various parts of the Ghostscript startup code.
483aca
-  %% Since each operator is a potential security vulnerability, and any operator listed here
483aca
-  %% is not required once the initialisation is complete and functions are bound, we undefine
483aca
-  %% the ones that aren't needed at runtime.
483aca
+  % This list of operators are used internally by various parts of the Ghostscript startup code.
483aca
+  % Since each operator is a potential security vulnerability, and any operator listed here
483aca
+  % is not required once the initialisation is complete and functions are bound, we undefine
483aca
+  % the ones that aren't needed at runtime.
483aca
   [
483aca
   /.callinstall /.callbeginpage /.callendpage
483aca
   /.currentstackprotect /.setstackprotect /.errorexec /.finderrorobject /.installsystemnames /.bosobject /.fontbbox
483aca
@@ -2297,12 +2302,12 @@ SAFER { .setsafeglobal } if
483aca
 } .bind executeonly def % must be bound and hidden for .forceundef
483aca
 
483aca
 /UndefinePDFOperators {
483aca
-  %% This list of operators are used internally by various parts of the Ghostscript PDF interpreter.
483aca
-  %% Since each operator is a potential security vulnerability, and any operator listed here
483aca
-  %% is not required once the initislisation is complete and functions are bound, we undefine
483aca
-  %% the ones that aren't needed at runtime.
483aca
-  %% This function is only called if DELAYBIND is true. It is a copy of the code at the end of pdf_main.ps
483aca
-  %% and must be maintained in parallel with it.
483aca
+  % This list of operators are used internally by various parts of the Ghostscript PDF interpreter.
483aca
+  % Since each operator is a potential security vulnerability, and any operator listed here
483aca
+  % is not required once the initislisation is complete and functions are bound, we undefine
483aca
+  % the ones that aren't needed at runtime.
483aca
+  % This function is only called if DELAYBIND is true. It is a copy of the code at the end of pdf_main.ps
483aca
+  % and must be maintained in parallel with it.
483aca
   [
483aca
   /.pdfawidthshow /.pdfwidthshow /.currentblackptcomp /.setblackptcomp
483aca
   /.setfillcolor /.setfillcolorspace /.setstrokecolor /.setstrokecolorspace /.currentrenderingintent /.setrenderingintent
483aca
@@ -2411,13 +2416,13 @@ $error /.nosetlocal //false put
483aca
 
483aca
 (END GLOBAL) VMDEBUG
483aca
 
483aca
-%% .savelocalstate is part of Display PostScript (if included). Part of the function of
483aca
-%% the .savelocalstate routine is to store the 'initial saved gstate' (savedinitialgstate)
483aca
-%% in systemdict. The code in dps1.c, gstate_check_space, disallows writing or creating
483aca
-%% gstates in global VM in certain conditions. If we execute setpagedevice before we
483aca
-%% reach this point, we must ensure that we do so using /..StartupGlobal so that
483aca
-%% the dictionary is defined in global VM, because the gstate contains a pointer to the
483aca
-%% device dictionary, and if that is allocated in local VM we will fail the gstate check.
483aca
+% .savelocalstate is part of Display PostScript (if included). Part of the function of
483aca
+% the .savelocalstate routine is to store the 'initial saved gstate' (savedinitialgstate)
483aca
+% in systemdict. The code in dps1.c, gstate_check_space, disallows writing or creating
483aca
+% gstates in global VM in certain conditions. If we execute setpagedevice before we
483aca
+% reach this point, we must ensure that we do so using /..StartupGlobal so that
483aca
+% the dictionary is defined in global VM, because the gstate contains a pointer to the
483aca
+% device dictionary, and if that is allocated in local VM we will fail the gstate check.
483aca
 /.savelocalstate where {
483aca
         % If we might create new contexts, save away copies of all dictionaries
483aca
         % referenced from systemdict that are stored in local VM,
483aca
@@ -2452,8 +2457,8 @@ currentdict /.shadingtypes .undef
483aca
 currentdict /.wheredict .undef
483aca
 currentdict /.renderingintentdict .undef
483aca
 
483aca
-%% If we are using DELAYBIND we have to defer the undefinition
483aca
-%% until .bindnow.
483aca
+% If we are using DELAYBIND we have to defer the undefinition
483aca
+% until .bindnow.
483aca
 DELAYBIND not {
483aca
   SAFER {
483aca
     //systemdict /SAFERUndefinePostScriptOperators get exec
483aca
@@ -2485,7 +2490,7 @@ DELAYBIND not {
483aca
   systemdict /.forceundef .undef	% ditto
483aca
 } if
483aca
 
483aca
-%% Can't remove this one until the last minute :-)
483aca
+% Can't remove this one until the last minute :-)
483aca
 DELAYBIND not {
483aca
 systemdict /.undef .undef
483aca
 } if
483aca
-- 
483aca
2.20.1
483aca