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

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