Bug 701894 - Regression? with doxygen generated .ps files.
Summary: Regression? with doxygen generated .ps files.
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: 9.50
Hardware: PC Linux
: P4 normal
Assignee: Chris Liddell (chrisl)
URL:
Keywords:
: 701988 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-11-11 17:56 UTC by ghostscript
Modified: 2019-12-13 11:23 UTC (History)
3 users (show)

See Also:
Customer:
Word Size: ---


Attachments
The generated ps file (148 bytes, application/postscript)
2019-11-11 17:56 UTC, ghostscript
Details
_form0.eps (47.19 KB, image/x-eps)
2019-11-11 18:00 UTC, ghostscript
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ghostscript 2019-11-11 17:56:36 UTC
Created attachment 18523 [details]
The generated ps file

Hello ghostscript-team,

I'm terrible sorry if this is not the place to post this, but I have a bit of a trouble to find the right place.

After a recent system upgrade I couldn't build any doxygen generated user documentation that included formulas. (ghostscript upgrade from 9.27-2 to 9.50)

```log
Generating directory documentation...
Generating bitmaps for formulas in HTML...
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Arch Linux) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./_formulas.tex
LaTeX2e <2019-10-01> patch level 1
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/08/27 v1.4j Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
[...]
(/usr/share/texmf-dist/tex/latex/newunicodechar/newunicodechar.sty)
(./_formulas.aux) [1] [2] [3] (./_formulas.aux) )
Output written on _formulas.dvi (3 pages, 748 bytes).
Transcript written on _formulas.log.
Generating image form_0.png for formula
Error: /undefinedfilename in (_form0.ps)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
Current allocation mode is local
Last OS error: Permission denied
GPL Ghostscript 9.50: Unrecoverable error, exit code 1
error: Problem running ghostscript gs -q -g178x66 -r384x384x -sDEVICE=ppmraw -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH -- _form0.ps. Check your installation!
Generating index page...
```

So I tried the mentioned command in the error output and got

```
gs -q -g178x66 -r384x384x -sDEVICE=ppmraw -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH -- _form0.ps
Error: /undefinedfilename in (_form0.ps)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
Current allocation mode is local
Last OS error: Permission denied
GPL Ghostscript 9.50: Unrecoverable error, exit code 1
```

Can you please help us identify the problem? I guess this file is ill-formed, what would we need to add / change to make it valid for new and old versions.

Thank you!

Original bug report at doxygen: https://github.com/doxygen/doxygen/issues/7290
Comment 1 ghostscript 2019-11-11 18:00:34 UTC
Created attachment 18524 [details]
_form0.eps
Comment 2 Robin Watts 2019-11-11 18:19:48 UTC
(In reply to ghostscript from comment #0)
> I'm terrible sorry if this is not the place to post this, but I have a bit
> of a trouble to find the right place.

This is a perfectly reasonable place. Another place would be the irc channel #ghostscript, where we might solve the problem with a bit of back and forth faster than doing via bugzilla, but this is OK.

> After a recent system upgrade I couldn't build any doxygen generated user
> documentation that included formulas. (ghostscript upgrade from 9.27-2 to
> 9.50)

The big change for 9.50 is the file security modifications. This basically adds additional controls onto what files gs can read and write.

> Error: /undefinedfilename in (_form0.ps)
> Operand stack:
> 
> Execution stack:
>    %interp_exit   .runexec2   --nostringval--   --nostringval--  
> --nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
> --nostringval--   false   1   %stopped_push
> Dictionary stack:
>    --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
> Current allocation mode is local
> Last OS error: Permission denied
> GPL Ghostscript 9.50: Unrecoverable error, exit code 1
> error: Problem running ghostscript gs -q -g178x66 -r384x384x -sDEVICE=ppmraw
> -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH -- _form0.ps. Check your
> installation!
> Generating index page...

OK. So that looks to me like it can't find the "_form0.ps" file.

That might be because such a file doesn't exist, or it might be because we are not permitted to READ from such a file.

> So I tried the mentioned command in the error output and got
> 
> ```
> gs -q -g178x66 -r384x384x -sDEVICE=ppmraw -sOutputFile=_form0.pnm -dNOPAUSE
> -dBATCH -- _form0.ps
> Error: /undefinedfilename in (_form0.ps)
> Operand stack:
> 
> Execution stack:
>    %interp_exit   .runexec2   --nostringval--   --nostringval--  
> --nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
> --nostringval--   false   1   %stopped_push
> Dictionary stack:
>    --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
> Current allocation mode is local
> Last OS error: Permission denied
> GPL Ghostscript 9.50: Unrecoverable error, exit code 1
> ```

First off, check to see if _form0.ps exists. If it doesn't, there's your problem.

If it does, try using:

  gs --permit-file-read=_form0.ps -q -g178x66 -r384x384x -sDEVICE=ppmraw -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH -- _form0.ps

and see if that solves the problem. If it does, then adding that path onto the list of paths allowed to be read should solve it.
Comment 3 Ken Sharp 2019-11-11 18:55:58 UTC
(In reply to Robin Watts from comment #2)

> > Error: /undefinedfilename in (_form0.ps)
> > Operand stack:
> > 
> > Execution stack:
> >    %interp_exit   .runexec2   --nostringval--   --nostringval--  
> > --nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
> > --nostringval--   false   1   %stopped_push
> > Dictionary stack:
> >    --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
> > Current allocation mode is local
> > Last OS error: Permission denied
> > GPL Ghostscript 9.50: Unrecoverable error, exit code 1
> > error: Problem running ghostscript gs -q -g178x66 -r384x384x -sDEVICE=ppmraw
> > -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH -- _form0.ps. Check your
> > installation!
> > Generating index page...
> 
> OK. So that looks to me like it can't find the "_form0.ps" file.

That's what undefinedfilename means, yes.
 
> > gs -q -g178x66 -r384x384x -sDEVICE=ppmraw -sOutputFile=_form0.pnm -dNOPAUSE
> > -dBATCH -- _form0.ps
> > Error: /undefinedfilename in (_form0.ps)
> > Operand stack:
> > 
> > Execution stack:
> >    %interp_exit   .runexec2   --nostringval--   --nostringval--  
> > --nostringval--   2   %stopped_push   --nostringval--   --nostringval--  
> > --nostringval--   false   1   %stopped_push
> > Dictionary stack:
> >    --dict:730/1123(ro)(G)--   --dict:0/20(G)--   --dict:76/200(L)--
> > Current allocation mode is local
> > Last OS error: Permission denied
> > GPL Ghostscript 9.50: Unrecoverable error, exit code 1
> > ```
> 
> First off, check to see if _form0.ps exists. If it doesn't, there's your
> problem.

The problem appears to be the use of '--'. If you remove that then _fomr0.ps will be found and will run. Of course it will then immediately fail with an invalidaccess error on _form0.eps because that file is not able to be read (permission has not been granted).

It looks like the '--'switch has been broken, but I have no idea why you are using it anyway in this setup, its not doing anything. Leave it off and I believe _form0.ps will be found as expected.

Which will then get you into the security issues Robin mentioned. _fomr0.ps executes the run operator on '_form0.eps'. Since PostScript is a programming language, that means its going to execute a file whose contents are unknown. With the release of 9.50 if you want to do that you need to explicitly tell Ghostscript you want to do so.

If I can make a tiny modification to Robin's suggestion:

   gs --permit-file-read=_form0.eps -q -g178x66 -r384x384x -sDEVICE=ppmraw
 -sOutputFile=_form0.pnm -dNOPAUSE -dBATCH _form0.ps

That allows form0.eps to be run, and removes the '--' switch which you don't need. Give that a whirl and I think it will work
Comment 4 Chris Liddell (chrisl) 2019-11-12 11:18:18 UTC
Sort of fixed in:

http://git.ghostscript.com/?p=user/chrisl/ghostpdl.git;a=commitdiff;h=24ec06a27df6


That commit fixes the "primary" file argument, that is, the file name that immediately follows "--". We cannot fix the other problem (that _form0.ps does "( _form0.eps) run" in the Postscript).

Security concerns mean allowing Postscript jobs to open/read/run/etc arbitrary other files is just not feasible. For instances like this, as discussed on IRC ( https://ghostscript.com/irclogs/2019/11/11.html ) there really is not option but the use the file access permissions options:

file:///home/cliddell/artifex/ghostpdl/doc/Use.htm#Safer

Disabling SAFER ( -dNOSAFER ) would also work, but is something we would strongly discourage as a security hazard.
Comment 5 Chris Liddell (chrisl) 2019-12-13 11:23:52 UTC
*** Bug 701988 has been marked as a duplicate of this bug. ***