Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 844115 - app-text/ghostscript-gpl built on Gentoo behaves differently from official build (app-text/poppler-data is missing extra files)
Summary: app-text/ghostscript-gpl built on Gentoo behaves differently from official bu...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Codec Project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 862133
  Show dependency tree
 
Reported: 2022-05-13 22:40 UTC by Guillaume Ayoub
Modified: 2022-10-04 09:09 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
PDF sample (gs-fail.pdf,3.31 KB, application/pdf)
2022-05-13 22:41 UTC, Guillaume Ayoub
Details
fixed ebuild (poppler-data-0.4.11-r1.ebuild,821 bytes, text/plain)
2022-10-01 00:41 UTC, John Wudrick
Details
Identity-H (Identity-H,7.64 KB, application/postscript)
2022-10-01 00:41 UTC, John Wudrick
Details
Identity-V (Identity-V,2.56 KB, application/postscript)
2022-10-01 00:42 UTC, John Wudrick
Details
Identity-UTF16-H (Identity-UTF16-H,1.19 KB, text/x-matlab)
2022-10-01 00:42 UTC, John Wudrick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume Ayoub 2022-05-13 22:40:51 UTC
Since ghostscript-gpl-9.56.1, the version built on Gentoo is buggy when reading PDF files. It gives results different from the official build and from the builds provided by other Linux and macOS distributions.

Reproducible: Always

Steps to Reproduce:
1. Build app-text/ghostscript-gpl-9.56.1 
2. gs -q -dNOPAUSE -dSAFER -dBATCH -sDEVICE=jpeg -sOutputFile=gs-fail-bad.jpg gs-fail.pdf
3. Download Ghostscript 9.56.1 official binary on https://www.ghostscript.com/releases/gsdnld.html
4. gs-9561-linux-x86_64 -q -dNOPAUSE -dSAFER -dBATCH -sDEVICE=jpeg -sOutputFile=gs-fail-good.jpg gs-fail.pdf
Actual Results:  
gs-fail-bad.jpg and gs-fail-good.jpg are different

Expected Results:  
gs-fail-bad.jpg and gs-fail-good.jpg are the same

The problem happens with many different documents. gs-fail.pdf is just one small example.

The problem also happens when generating different image formats (png…)

Note that Ghostscript 9.56.1 uses a new PDF interpreter by default (https://www.ghostscript.com/blog/pdfi.html). Even without this interpreter (ie. using -dNEWPDF=false), the rendering is sometimes buggy. It may or may not be related.

The problem doesn’t happen using the official binary on Gentoo, with Archlinux’ package or with Hombrew’s package (on macOS).

The bug breaks WeasyPrint’s tests on two different computers: https://github.com/Kozea/WeasyPrint/issues/1643


Portage 3.0.30 (python 3.9.12-final-0, default/linux/amd64/17.1/no-multilib, gcc-11.3.0, glibc-2.35-r4, 5.16.1-gentoo x86_64)
=================================================================
System uname: Linux-5.16.1-gentoo-x86_64-Intel-R-_Core-TM-_i7-10510U_CPU_@_1.80GHz-with-glibc2.35
KiB Mem:    24497584 total,    514812 free
KiB Swap:    4194300 total,   3998344 free
Timestamp of repository gentoo: Wed, 11 May 2022 14:30:01 +0000
Head commit of repository gentoo: d095d5bdbb688b1e3c31e1276134317623f85753
sh bash 5.1_p16
ld GNU ld (Gentoo 2.38 p4) 2.38
app-misc/pax-utils:        1.3.4::gentoo
app-shells/bash:           5.1_p16::gentoo
dev-lang/perl:             5.34.1-r3::gentoo
dev-lang/python:           3.8.13::gentoo, 3.9.12::gentoo, 3.10.4::gentoo
dev-lang/rust:             1.60.0::gentoo
dev-util/cmake:            3.23.1::gentoo
dev-util/meson:            0.61.4-r2::gentoo
sys-apps/baselayout:       2.8::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-apps/systemd:          250.5-r1::gentoo
sys-devel/autoconf:        2.13-r1::gentoo, 2.71-r1::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/gcc:             11.3.0::gentoo
sys-devel/gcc-config:      2.5-r1::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/llvm:            13.0.1::gentoo, 14.0.3::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  5.17-r1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.35-r4::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts: 
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-metamanifest: yes

local
    location: /var/db/repos/local
    masters: gentoo

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe -mtls-dialect=gnu"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=native -O2 -pipe -mtls-dialect=gnu"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-march=native -O2 -pipe -mtls-dialect=gnu"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O2 -pipe -mtls-dialect=gnu"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="fr_FR.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en fr"
MAKEOPTS="-j4"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
SHELL="/bin/fish"
USE="X a52 aac acl alsa amd64 bluetooth bzip2 cairo cli crypt dbus dri echo-cancel eds egl emacs ffmpeg flac fontconfig fortran freebox fribidi gif git gles2 gnome gnome-keyring gstreamer gtk gtk3 gtk4 harfbuzz http http2 iconv icu idn introspection ipv6 jpeg jpeg2k libglvnd libnotify libtirpc mp3 mpeg nautilus ncurses networkmanager nls nptl ogg opengl openmp openssl opus pam pcre pipewire png policykit pulseaudio python readline savedconfig screencast seccomp spell split-usr sqlite ssh ssl svg symlink systemd theora threads truetype udev udisks unicode user-session vaapi vala vorbis vpx vulkan wayland woff2 x264 x265 xattr zlib" ABI_X86="64" ADA_TARGET="gnat_2020" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="en fr" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python3_8 python3_9" RUBY_TARGETS="ruby31" USERLAND="GNU" VIDEO_CARDS="intel i965 iris" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 Guillaume Ayoub 2022-05-13 22:41:36 UTC
Created attachment 778649 [details]
PDF sample
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-05-13 22:43:50 UTC
Were older versions fine?
Comment 3 Guillaume Ayoub 2022-05-13 22:46:22 UTC
(In reply to Sam James from comment #2)
> Were older versions fine?

Yes, there’s no problem with 9.55.0.
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-02 05:35:22 UTC
(In reply to Guillaume Ayoub from comment #3)
> (In reply to Sam James from comment #2)
> > Were older versions fine?
> 
> Yes, there’s no problem with 9.55.0.

Could you try building from source and see if it makes any difference? Like, manually, w/oo ebuild, etc? Want to narrow it down as much as possible.
Comment 5 Guillaume Ayoub 2022-06-04 07:42:40 UTC
(In reply to Sam James from comment #4)
> (In reply to Guillaume Ayoub from comment #3)
> > (In reply to Sam James from comment #2)
> > > Were older versions fine?
> > 
> > Yes, there’s no problem with 9.55.0.
> 
> Could you try building from source and see if it makes any difference? Like,
> manually, w/oo ebuild, etc? Want to narrow it down as much as possible.

I’ve downloaded the source tarball and compiled it ("./configure", "make", no explicit option). 

The problem also appears with this manually compiled version. The problem is not in the ebuild… Do you have another idea to find where it comes from?
Comment 6 Guillaume Ayoub 2022-06-06 09:25:26 UTC
I’ve let Ghostscript’s configure use its own default C and C++ compilation options:

- C compiler: x86_64-pc-linux-gnu-gcc -DHAVE_RESTRICT=1 -DUSE_LIBPAPER -Wall -W
- C++ compiler: x86_64-pc-linux-gnu-g++ -std=c++17

It doesn’t fix the problem.
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-11 09:41:33 UTC
(In reply to Guillaume Ayoub from comment #5)
> (In reply to Sam James from comment #4)
> > (In reply to Guillaume Ayoub from comment #3)
> > > (In reply to Sam James from comment #2)
> > > > Were older versions fine?
> > > 
> > > Yes, there’s no problem with 9.55.0.
> > 
> > Could you try building from source and see if it makes any difference? Like,
> > manually, w/oo ebuild, etc? Want to narrow it down as much as possible.
> 
> I’ve downloaded the source tarball and compiled it ("./configure", "make",
> no explicit option). 
> 
> The problem also appears with this manually compiled version. The problem is
> not in the ebuild… Do you have another idea to find where it comes from?

I'm really struggling here. I've compared the ebuilds to Fedora and Arch's packaging, but it looks.. fine. And if it happens when building manually, it must be one of our dependencies, right?

But if the Fedora or Arch binaries work for you, given they don't statically link stuff, it means it must be in how it was built.

The only thing I can think of is some bundled library copy they're using, but it still doesn't make sense if a manual build fails with no patching.

We did have a bug with lcms2 a little while ago, but it got fixed upstream (and we'd backported the patch before they made a fix release even): bug 832520.
Comment 8 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-06-11 11:27:18 UTC
Perhaps if someone has some time, they could try using Fedora or Arch packages on Gentoo (if they are compatible with Gentoo's shared libraries).
Comment 9 Guillaume Ayoub 2022-06-12 09:09:55 UTC
(In reply to Michał Górny from comment #8)
> Perhaps if someone has some time, they could try using Fedora or Arch
> packages on Gentoo (if they are compatible with Gentoo's shared libraries).

Arch’s package has the bug when used on my Gentoo laptop. But there’s no bug on Arch.

(If anyone wants to try, download and unzip Arch’s ghostscript and libjpeg-turbo packages, and set LD_LIBRARY_PATH=<unzip-path>/usr/lib/ GS_LIB=<unzip-path>/usr/share/ghostscript/Resource/Init/ environment variables. Arch’s libjpeg-turbo package is not compatible with Gentoo’s.)
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-12 09:20:44 UTC
(In reply to Guillaume Ayoub from comment #9)
> (In reply to Michał Górny from comment #8)
> > Perhaps if someone has some time, they could try using Fedora or Arch
> > packages on Gentoo (if they are compatible with Gentoo's shared libraries).
> 
> Arch’s package has the bug when used on my Gentoo laptop. But there’s no bug
> on Arch.
> 
> (If anyone wants to try, download and unzip Arch’s ghostscript and
> libjpeg-turbo packages, and set LD_LIBRARY_PATH=<unzip-path>/usr/lib/
> GS_LIB=<unzip-path>/usr/share/ghostscript/Resource/Init/ environment
> variables. Arch’s libjpeg-turbo package is not compatible with Gentoo’s.)

Okay, I think this is helpful. Next step is to compare the versions dependencies of GS dependencies on Arch vs Gentoo (not the versions listed in the ebuild, just the versions of each dependency in reality that are installed).
Comment 11 Guillaume Ayoub 2022-06-15 16:06:00 UTC
(In reply to Sam James from comment #10)
> Okay, I think this is helpful. Next step is to compare the versions
> dependencies of GS dependencies on Arch vs Gentoo (not the versions listed
> in the ebuild, just the versions of each dependency in reality that are
> installed).

I’ve tried to find some differences, but nothing obvious.

OK. It’s time to find the source of the problem. FOR REAL.

It’s BISECT TIME 🤯.
Comment 12 Guillaume Ayoub 2022-06-15 17:03:02 UTC
The bug has been introduced by http://git.ghostscript.com/?p=ghostpdl.git;a=commit;h=42dca5ca192296b4cf40dd61f2eb61e062a1d449

Especially this part: http://git.ghostscript.com/?p=ghostpdl.git;a=blobdiff;f=base/fapi_ft.c;h=39dccc7d4f1d9ecdd9f34dcaca33a2cc3a76b74e;hp=d02453b795cdbce7972e93264613e5dbcf879589;hb=42dca5ca192296b4cf40dd61f2eb61e062a1d449;hpb=5e3eee0376626bc7d978b5136ac3f9d73d116bc5

Applying the reverse patch makes 9.56.1 work correctly for me.

Random thoughts:

- Arch’s package may work because it doesn’t remove in-tree freetype [1] as Gentoo’s ebuild does [2]. I’ve tried to keep the freetype folder in Gentoo’s ebuild, but it doesn’t work. Long story short: I have no idea of what’s going on.

- The sample attached in this bug uses small fonts (makes sense), but that’s probably not the case of bug 851141.

[1] https://github.com/archlinux/svntogit-packages/blob/packages/ghostscript/trunk/PKGBUILD#L51
[2] https://gitweb.gentoo.org/repo/gentoo.git/tree/app-text/ghostscript-gpl/ghostscript-gpl-9.56.1.ebuild#n74
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-22 23:13:24 UTC
(In reply to Guillaume Ayoub from comment #12)
> The bug has been introduced by
> http://git.ghostscript.com/?p=ghostpdl.git;a=commit;
> h=42dca5ca192296b4cf40dd61f2eb61e062a1d449
> 
> Especially this part:
> http://git.ghostscript.com/?p=ghostpdl.git;a=blobdiff;f=base/fapi_ft.c;
> h=39dccc7d4f1d9ecdd9f34dcaca33a2cc3a76b74e;
> hp=d02453b795cdbce7972e93264613e5dbcf879589;
> hb=42dca5ca192296b4cf40dd61f2eb61e062a1d449;
> hpb=5e3eee0376626bc7d978b5136ac3f9d73d116bc5
> 
> Applying the reverse patch makes 9.56.1 work correctly for me.
> 
> Random thoughts:
> 
> - Arch’s package may work because it doesn’t remove in-tree freetype [1] as
> Gentoo’s ebuild does [2]. I’ve tried to keep the freetype folder in Gentoo’s
> ebuild, but it doesn’t work. Long story short: I have no idea of what’s
> going on.
> 
> - The sample attached in this bug uses small fonts (makes sense), but that’s
> probably not the case of bug 851141.
> 
> [1]
> https://github.com/archlinux/svntogit-packages/blob/packages/ghostscript/
> trunk/PKGBUILD#L51
> [2]
> https://gitweb.gentoo.org/repo/gentoo.git/tree/app-text/ghostscript-gpl/
> ghostscript-gpl-9.56.1.ebuild#n74

Fantastic! Could you report it upstream?
Comment 14 Guillaume Ayoub 2022-06-23 07:26:18 UTC
(In reply to Sam James from comment #13)
> Fantastic! Could you report it upstream?

Before reporting the bug upstream, we’d probably like to solve the last mystery: why does it work on other distributions?

Ghostscript’s binary works on Gentoo, the distribution package (built from the sources) works on Arch. For now, there’s no evidence that the "bug" can be reproduced on any distribution other than Gentoo, and that’s a problem if we want the Ghostscript’s devs to reproduce and solve it.

As Arch’s package has the bug when used on Gentoo, we can assume that the root of the bug is in another package (Freetype?) that’s different when built on Gentoo and on Arch. If anyone has an idea to find where the problem is, I can spend more time on this issue, but currently I don’t really know what to do :/.
Comment 15 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-06-23 08:06:49 UTC
I would start by playing with freetype's USE flags.
Comment 16 Guillaume Ayoub 2022-06-26 15:48:48 UTC
(In reply to Michał Górny from comment #15)
> I would start by playing with freetype's USE flags.

While checking the differences of the build options of Freetype on Gentoo and Arch, I’ve tried to apply the patch on Gentoo’s package instead of building from the sources. This way, I thought I could at least have Ghostscript’s ebuild working on my computer without the bug.

But now, I’m desperate.

- When building 9.56.1 from the git repository (ghostpdl-9.56.1 tag), I get the bug.
- When building 9.56.1 from the git repository (ghostpdl-9.56.1 tag) with the reverse patch, I do not get the bug.
- When building 9.56.1 from the ebuild, I get the bug.
- When building 9.56.1 from the ebuild with the reverse patch, I GET THE BUG 😡.

I’ve checked everything. I can see that the patch is applied when building from the ebuild, I’m sure that the patch applied to the git repository is exactly the same as the one applied to the ebuild. But it doesn’t fix the bug for the ebuild, only for the git repository.

And of course, everything works WITHOUT the patch on other distributions, and even on Gentoo when we use the official build.

It doesn’t make sense.

I can try to play with Freetype’s USE flags, but I doubt that there’s something wrong with them from what I can say of Arch’s build options. Ghostscript includes its own copy of Freetype, I don’t know the differences with upstream and just "bisecting" these differences could take days. And that’s only for Freetype, but the same applies to other bundled libraries.

I’ll try different random things when I can find more time.
Comment 17 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-06-26 15:54:30 UTC
I can feel your pain.  Believe me, I know what you're going through and even more I'd like to thank you for trying to figure this out.
Comment 18 Larry the Git Cow gentoo-dev 2022-08-02 03:39:06 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a7e7e2e1e67ce3374bafba51b9cdd271f29b48d2

commit a7e7e2e1e67ce3374bafba51b9cdd271f29b48d2
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-08-02 03:38:32 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-08-02 03:38:57 +0000

    profiles: mask broken ghostscript-gpl-9.56.1
    
    We should've done this earlier, even.
    
    Bug: https://bugs.gentoo.org/844115
    Bug: https://bugs.gentoo.org/851141
    Signed-off-by: Sam James <sam@gentoo.org>

 profiles/package.mask | 4 ++++
 1 file changed, 4 insertions(+)
Comment 19 Matt Jolly gentoo-dev 2022-09-10 22:17:35 UTC
I've taken a brief look into this bug over the weekend.

My findings:

1. Repro'd failure on emerge build
2. Unable to repro failure when building the same tag from upstream git (output matches upstream binaries)

I removed the 'quiet' flag, and noted that we receive *different output* from each binary.


upstream binary:

```
GPL Ghostscript 9.56.1 (2022-04-04)
Copyright (C) 2022 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Processing pages 1 through 2.
Page 1
Page 2

```

git

```
GPL Ghostscript 9.56.1 (2022-04-04)
Copyright (C) 2022 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Unknown .defaultpapersize: (A4).
Processing pages 1 through 2.
Page 1
Page 2
```


emerge:

```
GPL Ghostscript 9.56.1 (2022-04-04)
Copyright (C) 2022 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Unknown .defaultpapersize: (A4).
Processing pages 1 through 2.
Page 1
Loading font TWQBVK (or substitute) from /usr/share/ghostscript/9.56.1/Resource/Font/NimbusSans-Regular
Loading font TWQBVK (or substitute) from /usr/share/ghostscript/9.56.1/Resource/Font/NimbusSans-Regular
Page 2
Loading font TWQBVK (or substitute) from /usr/share/ghostscript/9.56.1/Resource/Font/NimbusSans-Regular
Loading font TWQBVK (or substitute) from /usr/share/ghostscript/9.56.1/Resource/Font/NimbusSans-Regular
```

Based on the different outputs here, I suspect that something in the following function is causing the difference that we're seeing:

https://github.com/ArtifexSoftware/ghostpdl/blob/ghostpdl-9.56.1/pdf/pdf_font.c#L528

I'll need to dig into why that actually differs a bit later on today (if I have time). As a stretch goal, I'd like to work out why the upstream binary doesn't throw `Unknown .defaultpapersize: (A4).` while both compiled on my machine do; that might be a quick query for upstream though!
Comment 20 Guillaume Ayoub 2022-09-26 14:15:03 UTC
@Matt Thanks a lot for taking the time to find what’s wrong.

@all I’ve tried to compile the new 10.0.0 version, I get the same bug.
Comment 21 John Wudrick 2022-10-01 00:40:30 UTC
Ghostscript's official binary is built with bundled CMaps; on Gentoo, these are unbundled in favor of those provided by app-text/poppler-data. Ghostscript's CMaps include 3 files missing from poppler-data: Identity-H, Identity-V, and Identity-UTF16-H (CMap resources for the special-purpose Adobe Identity-0 ROS), and the lack of these files is causing this issue.

Fedora and Arch avoid this problem by using GS-bundled CMaps, while Debian (and older versions of Fedora) relies on CMaps from poppler-data (like Gentoo does) and includes the missing files in their poppler-data package, installing them to /usr/share/poppler/cMap. (According to Debian, upstream poppler-data refuses to include them.)

Two of these files are provided by Adobe Type Tools:
https://github.com/adobe-type-tools/cmap-resources/tree/master/Adobe-Identity-0/CMap

and the third is from Artifex themselves:
http://git.ghostscript.com/?p=ghostpdl.git;a=blob;f=Resource/CMap/Identity-UTF16-H;hb=HEAD

You can copy these 3 files to /usr/share/poppler/cMaps for a quick-and-dirty verification that they resolve the issue; by doing so, I was able to produce a match for gs-fail-good.jpg and pass the WeasyPrint test suite using ghostscript-gpl-9.56.1 (and 10.0). Including these files with poppler-data seems like the best approach. (As noted in Ghostscript's LICENSE file, Identity-UTF16-H is licensed under AGPL-3+.)
Comment 22 John Wudrick 2022-10-01 00:41:15 UTC
Created attachment 814879 [details]
fixed ebuild
Comment 23 John Wudrick 2022-10-01 00:41:57 UTC
Created attachment 814882 [details]
Identity-H
Comment 24 John Wudrick 2022-10-01 00:42:20 UTC
Created attachment 814885 [details]
Identity-V
Comment 25 John Wudrick 2022-10-01 00:42:44 UTC
Created attachment 814888 [details]
Identity-UTF16-H
Comment 26 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-10-01 06:37:24 UTC
Thanks a ton for figuring this out!
Comment 27 Larry the Git Cow gentoo-dev 2022-10-01 06:56:25 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=21675840cadb15ceb9e3597f43da2f199d70240a

commit 21675840cadb15ceb9e3597f43da2f199d70240a
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-01 06:54:40 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-01 06:54:40 +0000

    profiles: unmask ghostscript 9.56
    
    Closes: https://bugs.gentoo.org/844115
    Closes: https://bugs.gentoo.org/851141
    Signed-off-by: Sam James <sam@gentoo.org>

 profiles/package.mask | 4 ----
 1 file changed, 4 deletions(-)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0ecd6cf254f4d76419fd05f80095f134513f7856

commit 0ecd6cf254f4d76419fd05f80095f134513f7856
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-01 06:54:16 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-01 06:54:16 +0000

    app-text/ghostscript-gpl: depend on newer poppler-data w/ needed files
    
    Closes: https://bugs.gentoo.org/844115
    Signed-off-by: Sam James <sam@gentoo.org>

 ...ostscript-gpl-9.56.1-r1.ebuild => ghostscript-gpl-9.56.1-r2.ebuild} | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Additionally, it has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f7d3daf96af5d450b3f983df77129c5aeac3c376

commit f7d3daf96af5d450b3f983df77129c5aeac3c376
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-01 06:49:48 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-01 06:52:03 +0000

    app-text/poppler-data: add additional cMaps files needed by ghostscript
    
    Quoting John from the Bug;
    >Ghostscript's official binary is built with bundled CMaps; on Gentoo, these are unbundled
    >in favor of those provided by app-text/poppler-data. Ghostscript's CMaps include 3 files
    >missing from poppler-data: Identity-H, Identity-V, and Identity-UTF16-H (CMap
    >resources for the special-purpose Adobe Identity-0 ROS), and the lack of these files is causing this issue.
    >
    >Fedora and Arch avoid this problem by using GS-bundled CMaps, while Debian
    >(and older versions of Fedora) relies on CMaps from poppler-data (like Gentoo does)
    >and includes the missing files in their poppler-data package, installing them to
    >/usr/share/poppler/cMap. (According to Debian, upstream poppler-data refuses to include them.)
    >
    >Two of these files are provided by Adobe Type Tools:
    >https://github.com/adobe-type-tools/cmap-resources/tree/master/Adobe-Identity-0/CMap
    >
    >and the third is from Artifex themselves:
    >http://git.ghostscript.com/?p=ghostpdl.git;a=blob;f=Resource/CMap/Identity-UTF16-H;hb=HEAD
    >
    >You can copy these 3 files to /usr/share/poppler/cMaps for a quick-and-dirty verification that
    >they resolve the issue; by doing so, I was able to produce a match for gs-fail-good.jpg and
    >pass the WeasyPrint test suite using ghostscript-gpl-9.56.1 (and 10.0). Including
    >these files with poppler-data seems like the best approach. (As noted in
    >Ghostscript's LICENSE file, Identity-UTF16-H is licensed under AGPL-3+.)
    
    Bug: https://bugs.gentoo.org/844115
    Thanks-to: John Wudrick <prochronism@gmail.com>
    Signed-off-by: Sam James <sam@gentoo.org>

 app-text/poppler-data/Manifest                     |  1 +
 .../poppler-data/poppler-data-0.4.11-r1.ebuild     | 27 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)
Comment 28 Larry the Git Cow gentoo-dev 2022-10-01 08:33:03 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3bb47ccd664800bbac42aa90e70ab73058482bd7

commit 3bb47ccd664800bbac42aa90e70ab73058482bd7
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-01 07:20:12 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-01 08:32:50 +0000

    dev-python/weasyprint: update ghostscript test dep
    
    Bug: https://bugs.gentoo.org/844115
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-python/weasyprint/weasyprint-55.0.ebuild | 5 ++++-
 dev-python/weasyprint/weasyprint-56.0.ebuild | 5 ++++-
 dev-python/weasyprint/weasyprint-56.1.ebuild | 5 ++++-
 3 files changed, 12 insertions(+), 3 deletions(-)
Comment 29 Larry the Git Cow gentoo-dev 2022-10-02 03:15:18 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e22155a75b4d1b45115719ea6c1db112614b449d

commit e22155a75b4d1b45115719ea6c1db112614b449d
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-02 03:14:41 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-02 03:14:41 +0000

    dev-python/weasyprint: adjust ghostscript dep
    
    I made an error in the poppler-data original fix, so depend on fixed
    GS again (with a fixed dep).
    
    Closes: https://bugs.gentoo.org/844115
    Closes: https://bugs.gentoo.org/851141
    Closes: https://bugs.gentoo.org/873889
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-python/weasyprint/weasyprint-55.0.ebuild | 2 +-
 dev-python/weasyprint/weasyprint-56.0.ebuild | 2 +-
 dev-python/weasyprint/weasyprint-56.1.ebuild | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=541c89d3edb13847d272b6b700fde7505830dea0

commit 541c89d3edb13847d272b6b700fde7505830dea0
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-02 03:14:08 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-02 03:14:08 +0000

    app-text/ghostscript-gpl: crank up poppler-data dep again
    
    I typo'd the paths previously.
    
    Closes: https://bugs.gentoo.org/844115
    Closes: https://bugs.gentoo.org/851141
    Closes: https://bugs.gentoo.org/873889
    Signed-off-by: Sam James <sam@gentoo.org>

 ...hostscript-gpl-9.56.1-r2.ebuild => ghostscript-gpl-9.56.1-r3.ebuild} | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f12b8ad09be64a20685b7c87fdb4dbbc2b7f8a56

commit f12b8ad09be64a20685b7c87fdb4dbbc2b7f8a56
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-02 03:12:40 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-02 03:13:39 +0000

    app-text/poppler-data: fix extra file paths
    
    Closes: https://bugs.gentoo.org/844115
    Closes: https://bugs.gentoo.org/851141
    Closes: https://bugs.gentoo.org/873889
    Fixes: f7d3daf96af5d450b3f983df77129c5aeac3c376
    Signed-off-by: Sam James <sam@gentoo.org>

 app-text/poppler-data/Manifest                                          | 2 +-
 .../{poppler-data-0.4.11-r1.ebuild => poppler-data-0.4.11-r2.ebuild}    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Comment 30 Guillaume Ayoub 2022-10-03 09:03:02 UTC
Thanks a lot for the work done to close this bug.

I’ve updated poppler-data and ghostscript, I have the new Identity-* files in /usr/share/poppler/cMaps, but unfortunately ghostscript-10 (installed from ebuild) still gives the wrong rendering with the "Loading font TWQBVK (or substitute) from …" messages.

Did I forget to do something?
Comment 31 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-04 01:13:41 UTC
(In reply to Guillaume Ayoub from comment #30)
> Thanks a lot for the work done to close this bug.
> 
> I’ve updated poppler-data and ghostscript, I have the new Identity-* files
> in /usr/share/poppler/cMaps, but unfortunately ghostscript-10 (installed
> from ebuild) still gives the wrong rendering with the "Loading font TWQBVK
> (or substitute) from …" messages.
> 
> Did I forget to do something?

Huh. Good question. I assumed everything was fine because the weasyprint tests passed now.
Comment 32 Guillaume Ayoub 2022-10-04 08:54:19 UTC
(In reply to Sam James from comment #31)
> (In reply to Guillaume Ayoub from comment #30)
> > Thanks a lot for the work done to close this bug.
> > 
> > I’ve updated poppler-data and ghostscript, I have the new Identity-* files
> > in /usr/share/poppler/cMaps, but unfortunately ghostscript-10 (installed
> > from ebuild) still gives the wrong rendering with the "Loading font TWQBVK
> > (or substitute) from …" messages.
> > 
> > Did I forget to do something?
> 
> Huh. Good question. I assumed everything was fine because the weasyprint
> tests passed now.

I’ve found what’s wrong: ghostscript-gpl-10.0.0 installs files in /usr/share/ghostscript/10.00.0, but the CMap folder is installed in /usr/share/ghostscript/10.0.0 (one 0 is missing).

Moving the folder into 10.00.0 fixes the problem.
Comment 33 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-10-04 09:02:55 UTC
(In reply to Guillaume Ayoub from comment #32)
> (In reply to Sam James from comment #31)
> > (In reply to Guillaume Ayoub from comment #30)
> > > Thanks a lot for the work done to close this bug.
> > > 
> > > I’ve updated poppler-data and ghostscript, I have the new Identity-* files
> > > in /usr/share/poppler/cMaps, but unfortunately ghostscript-10 (installed
> > > from ebuild) still gives the wrong rendering with the "Loading font TWQBVK
> > > (or substitute) from …" messages.
> > > 
> > > Did I forget to do something?
> > 
> > Huh. Good question. I assumed everything was fine because the weasyprint
> > tests passed now.
> 
> I’ve found what’s wrong: ghostscript-gpl-10.0.0 installs files in
> /usr/share/ghostscript/10.00.0, but the CMap folder is installed in
> /usr/share/ghostscript/10.0.0 (one 0 is missing).
> 
> Moving the folder into 10.00.0 fixes the problem.

Nice find, but now I'm wondering how to detect something like this, given the tarball really is 10.00.0. I guess I can check what folder in ${ED}/usr/share/ghostscript/* exists and use that for the symlink.
Comment 34 Larry the Git Cow gentoo-dev 2022-10-04 09:09:06 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=442db4d45a15b497cf43e75e3ad38ae90aaaabbc

commit 442db4d45a15b497cf43e75e3ad38ae90aaaabbc
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-10-04 09:08:21 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-10-04 09:08:59 +0000

    app-text/ghostscript-gpl: fix version used for /usr/share/poppler/* symlink
    
    Sometimes it deviates from the actual tarball & tag version, apparently.
    
    Closes: https://bugs.gentoo.org/844115
    Thanks-to: Guillaume Ayoub <guillaume@yabz.fr>
    Signed-off-by: Sam James <sam@gentoo.org>

 ...stscript-gpl-10.0.0.ebuild => ghostscript-gpl-10.0.0-r1.ebuild} | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)