Ghostscript fails to convert PBM files to PDF. Attempts were made with
3 different PBM files:
1) scanner-made PDF → (pdfimages -all) → (unpaper) → PBM → (ghostscript/pdfwrite) → error
2) tex → (LaTeX) → PDF → (ghostscript/pbm) → PBM → (ghostscript/pdfwrite) → error
3) (imagemagick) → PBM → (ghostscript/pdfwrite) → error
This seems to show that PBMs of any kind produce an error when using
the PDFwrite driver. Case 2 is interesting because it shows
Ghostscript’s own output is fed back into it and it can’t handle it.
Case 3 is demonstrated below because it requires no source file to
start with (ImageMagick gives a way to generate an arbitrary image
on-the-fly). So it’s easy to reproduce as long as ImageMagick is
installed.
===8<------------------------------
$ convert logo: -colors 2 -colorspace gray -normalize pbm:im_logo.pbm
$ gs -sDEVICE=pdfwrite -q -r300 -dSCALE=1 -o im_logo.pdf -- /usr/share/ghostscript/9.53.3/lib/viewpbm.ps im_logo.pbm
Error: /invalidfileaccess in --file--
Operand stack:
(im_logo.pbm) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval--
Dictionary stack:
--dict:734/1123(ro)(G)-- --dict:0/20(G)-- --dict:87/200(L)-- --dict:0/20(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 10282
GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
===8<------------------------------
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. I also retried case 3 but using a PPM
instead, which also failed:
===8<------------------------------
$ convert logo: -colors 2 -colorspace gray -normalize pbm:im_logo.ppm
$ gs -sDEVICE=pdfwrite -q -r300 -dSCALE=1 -o im_logo_ppm.pdf -- /usr/share/ghostscript/9.53.3/lib/viewpbm.ps im_logo.ppm
Error: /invalidfileaccess in --file--
Operand stack:
(im_logo.ppm) (r)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1990 1 3 %oparray_pop 1989 1 3 %oparray_pop 1977 1 3 %oparray_pop 1833 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval--
Dictionary stack:
--dict:734/1123(ro)(G)-- --dict:0/20(G)-- --dict:87/200(L)-- --dict:0/20(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 10282
GPL Ghostscript 9.53.3: Unrecoverable error, exit code 1
===8<------------------------------
-- System Information:
Debian Release: 11.4
APT prefers stable-updates
APT policy: (990, 'stable-updates'), (990, 'stable-security'), (990, 'testing'), (990, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 5.10.0-16-amd64 (SMP w/2 CPU threads)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages ghostscript depends on:
ii libc6 2.31-13+deb11u3
ii libgs9 9.53.3~dfsg-7+deb11u2
ghostscript recommends no packages.
Versions of packages ghostscript suggests:
ii ghostscript-x 9.53.3~dfsg-7+deb11u2
-- no debconf information
> Therefore please report the issue upstream.
I just happened to have an account on the upstream bug tracker that
still works, so I reported here:
https://bugs.ghostscript.com/show_bug.cgi?id=705699
But I should say this it’s not normal procedure for Debian maintainers
to ask bug reporters to mirror their report upstream according to the
section “Don't file bugs upstream” on this page:
https://www.debian.org/Bugs/Reporting
If upstream had been a place like Github (or even worse: gitlab.com),
I would not have created an account on those forges to report a bug.
In principle, it should be automated so a Debian maintainer can mirror
bugs upstream with a simple keystroke or click, ideally.