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

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