Summary: | “Error: /invalidfileaccess in --file--” when converting PBM file to PDF | ||
---|---|---|---|
Product: | Ghostscript | Reporter: | alt.d2-9os82yc7 |
Component: | PDF Writer | Assignee: | Default assignee <ghostpdl-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P4 | ||
Version: | 9.53.3 | ||
Hardware: | PC | ||
OS: | Linux | ||
Customer: | Word Size: | --- |
Description
alt.d2-9os82yc7
2022-07-31 19:33:16 UTC
(In reply to alt.d2-9os82yc7 from comment #0) > Ghostscript fails to convert PBM files to PDF. Attempts were made with > 3 different PBM files: Ghostscript doesn't handle PBM as an input format, just PostScript and PDF. > $ gs -sDEVICE=pdfwrite -q -r300 -dSCALE=1 -o im_logo.pdf -- > /usr/share/ghostscript/9.53.3/lib/viewpbm.ps im_logo.pbm Right, so this is more useful. You are using the viewpbm PostScript program to read the PBM file, you aren't reading it with Ghostscript. The viewpbm.ps program opens the file using the normal PostScript file handling operators: /pf fname (r) file def Recent versions of Ghostscript require you to either use -dNOSAFER or specify any files which the interpreter is permitted to access on the command line. Note that you cannot specify the files which a PostScript program is allowed to open inside the PostScript program itself, that would obviously be insecure. So viewpbm.ps can't add the files itself, it has to be on the command line. If you add --permit-file-read=<full path to logo.pbm> to the command line I suspect your file will run correctly. Or add -dNOSAFER, but I would not normally recommend that, it is probably safe enough when running the viewpbm.ps program, assuming you are certain that it is the one supplied by us, and trust us :-) > It’s worth noting that case 2 has no problem if the middle step uses > the ppmraw driver instead of the pbm driver. So I thought perhaps a > workaround would be to convert the PBM file produced by unpaper (case > 1) to PPM, then feed the PPM file into GS -- but no, the same > “invalidfileaccess” occurs. For the same reason, the PostScript program isn't permitted to access random files on the file system. > This was originally reported here: > > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1016424 > > but regarded by the Debian maintainer as an upstream bug. I don't see it as a bug at all, it's expected behaviour. You need to tell the interpreter that the program is permitted to access the file(s). When using Ghostscript to open PostScript programs we automatically add the name of the file containing the PostScript program (assuming it is a file) to the list of files which can be accessed (so running viewpbm.ps doesn't require explicit permission). For convenience we also add other files automatically, such as the contents of fontmap and cidfmap files, but not anything else. The way the viewpbm.ps program works, you need to add any of the files you expect the program to open to the list of permitted files yourself. Or use -dNOSAFER. Presumably convert could be modified to add the PBM filename to the command line with --permit-file-read. I'll look at changing the Usage string in the viewpbm.ps program though. Updated a number of the view*.ps programs here to include the requirement (since version 9.50) to use either -dNOSAFER or --permit-file-read so that the interpreter is permitted to read the input file. This is now included as part of the 'Usage' if the program has one, or in the comments if that is where the example is. |