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