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
Created attachment 778649 [details] PDF sample
Were older versions fine?
(In reply to Sam James from comment #2) > Were older versions fine? Yes, there’s no problem with 9.55.0.
(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.
(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’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.
(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.
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).
(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.)
(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).
(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 🤯.
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
(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?
(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 :/.
I would start by playing with freetype's USE flags.
(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.
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.
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(+)