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

From: Ikumi Keita <[email-masked]>
Date: Tue, 15 Oct 2019 01:48:52 +0900

Hi Chris,

>>>>> Chris Liddell <[email-masked]> writes:
> 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.

Thank you very much, this basically sorts out things fine!

>> **** WARNING: .lockfileaccess or .setsafe called ****
>> **** when file access controls are already active ****

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

This warning is problematic for preview-latex because preview-latex
regards it as an error and does not pick up the associated image file
into emacs buffer.  So I changed an element in the initial command
string given to ghostscript from
{DELAYSAFER{.setsafe}if}
to just
{}
in order to suppress the warning.  This worked for me.  However, I'm
just doing try&error method and I cannot tell whether this change leads
to security hole for earlier version of ghostscript.  Can you tell about
it?

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

A brief survey shows that this command line option does not exist in
Use.html of gs 9.27.  So I suppose we should refrain from using it in
preview-latex for compatibility with earlier gs.

> 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.

I'm not sure what those parentheses are for.  Maybe those are "quotes"
for PS language and "consumed" by ghostscript?

> 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.

Agreed.  In general, preview-latex needs multiple image files for
multiple math formulae in the latex document.  As far as I understand,
preview-latex invokes gs only once for those image files and gives input
to its prompt "GS>" to produce one image file, and waits the next prompt
to come up, and gives another input to it to produce another image
file,... and repeats similar cycle until all image files are generated.

So I think that the error message for "...pr1-1.png" was injected just
after preview-latex gave input for "..pr1-2.png", and those were
recorded in the emacs buffer for inter-process communication in that
order.

Best regards,
Ikumi Keita