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

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