Subject: Re: [gs-devel] Recent ghostscript broke preview-latex again

From: Chris Liddell <[email-masked]>
Date: Mon, 14 Oct 2019 15:41:35 +0100

On 14/10/2019 12:40, Ikumi Keita wrote:
> Hi Chris,
> 
>>>>>> Chris Liddell <[email-masked]> writes:
>> Before you call .locksafe, adding something like:
> 
>> systemdict /.addcontrolpath known
>> {
>>   /PermitFileReading (bbb.pdf) .addcontrolpath
>>   /PermitFileReading (bbb.prv/tmp0UabeI/preview.dsc) .addcontrolpath
>> } if
> 
> Thank you, this improves the situation.  However, preview-latex still
> does not work.  Ghostscript does not produce PNG files we expect and
> sometimes raises errors.  I quote a sample error at the last of this
> message.
> 
> I have an impression that gs fails to write out PNG files at specified
> paths due to restricted permission about file operation.
> 
> Regards,
> Ikumi Keita
> 
> /home/keita/gs/bin/gs -dOutputFile\=\(bbb.prv/tmp821SQO/pr1-2.png\) -q -dDELAYSAFER -dNOPAUSE -DNOPLATFONTS -dPrinted -dTextAlphaBits\=4 -dGraphicsAlphaBits\=4 -sDEVICE\=png16m -r108.606x108.587
> GS>systemdict /.addcontrolpath known {
>   /PermitFileReading (bbb.pdf) .addcontrolpath
>   /PermitFileReading (bbb.prv/tmp821SQO/preview.dsc) .addcontrolpath
> } if
> {<</PermitFileReading[(bbb.pdf)(bbb.prv/tmp821SQO/preview.dsc)]>> setuserparams .locksafe} stopped pop {DELAYSAFER{.setsafe}if}stopped pop/.preview-BP currentpagedevice/BeginPage get dup null eq{pop{pop}bind}if def<</BeginPage{currentpagedevice/PageSize get dup 0 get 1 ne exch 1 get 1 ne or{.preview-BP gsave 1 1 0.878431 setrgbcolor clippath fill grestore }{pop}ifelse}bind/PageSize[1 1]>>setpagedevice/preview-do{/.preview-ST[count 4 roll save]def dup length 0 eq{pop}{setpagedevice}{ifelse exec}stopped{handleerror quit}if .preview-ST aload pop restore}bind def  (bbb.prv/tmp821SQO/preview.dsc)(r)file /.preview-ST 1 index def dup 0 setfileposition 499()/SubFileDecode filter cvx exec .preview-ST dup dup 550 setfileposition 52()/SubFileDecode filter cvx<<>>preview-do
> 
>  **** WARNING: .lockfileaccess or .setsafe called ****
>  **** when file access controls are already active ****
> GPL Ghostscript GIT PRERELEASE 9.29: **** Could not open the file 'bbb.prv/tmp821SQO/pr1-1.png'.
> Error: /invalidfileaccess in --showpage--
> Operand stack:
>    1   true
> Execution stack:
>    %interp_exit   .runexec2   --nostringval--   showpage   --nostringval--   2   %stopped_push   --nostringval--   showpage   %loop_continue   showpage   showpage   false   1   %stopped_push   .runexec2   --nostringval--   showpage   --nostringval--   2   %stopped_push   --nostringval--   showpage   false   1   %stopped_push   --nostringval--   showpage   4   1   3   showpage   %for_pos_int_continue   1965   1   7   %oparray_pop   showpage   showpage   1824   0   9   %oparray_pop   showpage   showpage
> Dictionary stack:
>    --dict:731/1123(ro)(G)--   --dict:1/20(G)--   --dict:84/200(L)--   --dict:84/200(L)--   --dict:135/256(ro)(G)--   --dict:315/325(ro)(G)--   --dict:33/64(L)--   --dict:6/9(L)--   --dict:6/20(L)--
> Current allocation mode is local
> Last OS error: Permission denied

The warning is benign, although it does indicate that you can calling
.setsafe when SAFER is already active.

But there are some things that are confusing.

First, on your command line, your output file is in parentheses, but the
file name in the error message does not have parentheses. Secondly, the
file name on your command line is "bbb.prv/tmp821SQO/pr1-2.png" but the
one in the error is "bbb.prv/tmp821SQO/pr1-1.png". So, clearly not the
same file.

The revised file access controls includes control over output files, so
it is important the file names match, in these circumstances.

If you are changing the output file name dynamically, from the one on
the command line, you could add the output directory to the permitted
write directories:

systemdict /.addcontrolpath known
{
  /PermitFileReading (bbb.pdf) .addcontrolpath
  /PermitFileReading (bbb.prv/tmp0UabeI/preview.dsc) .addcontrolpath
  /PermitFileWriting (bbb.prv/tmp821SQO/) .addcontrolpath
} if

(Note the trailing '/' on the writable path.

This can also be done on the command line:
--permit-file-write="bbb.prv/tmp821SQO/"

Chris