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

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