lualatex incorrect version of zlib

Hello,

On a fresh installation of FreeBSD 14.0, I get the following error message using lualatex :

Running `LaTeX' on `Real World OCaml' with ``lualatex --jobname=Real\ World\ OCaml -file-line-error --synctex=1 -interaction=nonstopmode Real\ World\ OCaml.tex''
PANIC: unprotected error in call to Lua API (zlib library version does not match - header: 1.3, library: 1.3.1)

This is the outputs for the following commands :
1 - freebsd-version -kru
2 - pkg -vv
3 - pkg info tex-luatex

==============================
freebsd-version -kru
14.0-STABLE
14.0-STABLE
14.0-STABLE
==============================
pkg -vv
Version : 1.21.1
PKG_DBDIR = "/var/db/pkg";
PKG_CACHEDIR = "/var/cache/pkg";
PORTSDIR = "/usr/ports";
INDEXDIR = "";
INDEXFILE = "INDEX-14";
HANDLE_RC_SCRIPTS = false;
DEFAULT_ALWAYS_YES = false;
ASSUME_ALWAYS_YES = false;
REPOS_DIR [
"/etc/pkg/",
"/usr/local/etc/pkg/repos/",
]
PLIST_KEYWORDS_DIR = "";
SYSLOG = true;
ABI = "FreeBSD:14:amd64";
ALTABI = "freebsd:14:x86:64";
DEVELOPER_MODE = false;
VULNXML_SITE = "http://vuxml.freebsd.org/freebsd/vuln.xml.xz";
FETCH_RETRY = 3;
PKG_PLUGINS_DIR = "/usr/local/lib/pkg/";
PKG_ENABLE_PLUGINS = true;
PLUGINS [
]
DEBUG_SCRIPTS = false;
PLUGINS_CONF_DIR = "/usr/local/etc/pkg/";
PERMISSIVE = false;
REPO_AUTOUPDATE = true;
NAMESERVER = "";
HTTP_USER_AGENT = "pkg/1.21.1";
EVENT_PIPE = "";
FETCH_TIMEOUT = 30;
UNSET_TIMESTAMP = false;
SSH_RESTRICT_DIR = "";
PKG_ENV {
}
PKG_SSH_ARGS = "";
DEBUG_LEVEL = 0;
ALIAS {
all-depends = "query %dn-%dv";
annotations = "info -A";
build-depends = "info -qd";
cinfo = "info -Cx";
comment = "query -i \"%c\"";
csearch = "search -Cx";
desc = "query -i \"%e\"";
download = "fetch";
iinfo = "info -ix";
isearch = "search -ix";
prime-list = "query -e '%a = 0' '%n'";
prime-origins = "query -e '%a = 0' '%o'";
leaf = "query -e '%#r == 0' '%n-%v'";
list = "info -ql";
noauto = "query -e '%a == 0' '%n-%v'";
options = "query -i \"%n - %Ok: %Ov\"";
origin = "info -qo";
orphans = "version -vRl?";
provided-depends = "info -qb";
rall-depends = "rquery %dn-%dv";
raw = "info -R";
rcomment = "rquery -i \"%c\"";
rdesc = "rquery -i \"%e\"";
required-depends = "info -qr";
roptions = "rquery -i \"%n - %Ok: %Ov\"";
shared-depends = "info -qB";
show = "info -f -k";
size = "info -sq";
unmaintained = "query -e '%m = \"ports@FreeBSD.org\"' '%o (%w)'";
runmaintained = "rquery -e '%m = \"ports@FreeBSD.org\"' '%o (%w)'";
}
CUDF_SOLVER = "";
SAT_SOLVER = "";
RUN_SCRIPTS = true;
CASE_SENSITIVE_MATCH = false;
LOCK_WAIT = 1;
LOCK_RETRIES = 5;
SQLITE_PROFILE = false;
WORKERS_COUNT = 0;
READ_LOCK = false;
IP_VERSION = 0;
AUTOMERGE = true;
VERSION_SOURCE = "";
CONSERVATIVE_UPGRADE = true;
PKG_CREATE_VERBOSE = false;
AUTOCLEAN = false;
DOT_FILE = "";
REPOSITORIES {
}
VALID_URL_SCHEME [
"pkg+http",
"pkg+https",
"https",
"http",
"file",
"ssh",
"tcp",
]
ALLOW_BASE_SHLIBS = false;
WARN_SIZE_LIMIT = 1048576;
METALOG = "";
OSVERSION = 1400509;
IGNORE_OSVERSION = false;
BACKUP_LIBRARIES = false;
BACKUP_LIBRARY_PATH = "/usr/local/lib/compat/pkg";
PKG_TRIGGERS_DIR = "/usr/local/share/pkg/triggers";
PKG_TRIGGERS_ENABLE = true;
AUDIT_IGNORE_GLOB [
]
AUDIT_IGNORE_REGEX [
]
COMPRESSION_FORMAT = "";
COMPRESSION_LEVEL = -1;
ARCHIVE_SYMLINK = false;
REPO_ACCEPT_LEGACY_PKG = false;
FILES_IGNORE_GLOB [
]
FILES_IGNORE_REGEX [
]


Repositories:
FreeBSD: {
url : "pkg+https://pkg.freebsd.org/FreeBSD:14:amd64/latest",
enabled : yes,
priority : 0,
mirror_type : "SRV",
signature_type : "FINGERPRINTS",
fingerprints : "/usr/share/keys/pkg"
}
==============================
pkg info tex-luatex
tex-luatex-1.16.0_1
Name : tex-luatex
Version : 1.16.0_1
Installed on : Mon Apr 8 19:14:08 2024 CEST
Origin : print/tex-luatex
Architecture : FreeBSD:14:amd64
Prefix : /usr/local
Categories : print
Licenses :
Maintainer : tex@FreeBSD.org
WWW : UNKNOWN
Comment : Extended version of pdfTeX using Lua
Shared Libs required:
libzzip.so.13
libtexluajit.so.2
libtexlua53.so.5
libpng16.so.16
libkpathsea.so.6
libharfbuzz.so.0
libgraphite2.so.3
Annotations :
FreeBSD_version: 1400097
build_timestamp: 2024-03-26T10:31:28+0000
built_by : poudriere-git-3.4.1-1-g1e9f97d6
port_checkout_unclean: no
port_git_hash : 157c391cc1
ports_top_checkout_unclean: no
ports_top_git_hash: 9ee7b88dab
repo_type : binary
repository : FreeBSD
Flat size : 147MiB
Description :
LuaTeX is an extended version of pdfTeX using Lua as an embedded
scripting language. The LuaTeX projects main objective is to provide
an open and configurable variant of TeX while at the same time
offering downward compatibility.
 
luatex is dynamically linked with libz. See below (run on a 13.4 system):
sh:
% ldd /usr/local/bin/luatex
/usr/local/bin/luatex:
        libtexlua53.so.5 => /usr/local/lib/libtexlua53.so.5 (0x7a0be99d000)
        libzzip.so.13 => /usr/local/lib/libzzip.so.13 (0x7a0bd727000)
        libpng16.so.16 => /usr/local/lib/libpng16.so.16 (0x7a0bdaa8000)
        libz.so.6 => /lib/libz.so.6 (0x7a0bfedd000)                                   <--------
        libkpathsea.so.6 => /usr/local/lib/libkpathsea.so.6 (0x7a0bf789000)
        libm.so.5 => /lib/libm.so.5 (0x7a0c0fbc000)
        libc.so.7 => /lib/libc.so.7 (0x7a0c1e87000)
        [vdso] (0x7ffffffff650)

The FreeBSD ports system tracks when dependent version of libraries in the ports tree are changed, but any given port will not always know it needs to be rebuilt when a base library (like libz) changes. The ports system just doesn't normally track when base system libraries get an incremental update. It's more along the lines of "abundance of caution" recommendations to "rebuild all ports" after you do a base OS update. In reality a particular port might NOT need to be rebuilt because an updated library change may still be ABI / API compatible with the previously installed version of the shared library.

In your case, it looks like the luatex binary was built against a libz that was version 1.3:

sh:
% grep define.ZLIB_VERSION /usr/include/zlib.h
#define ZLIB_VERSION "1.3"

This may not actually be a problem. The changes from 1.3 and 1.3.1 are probably not incompatible (although I didn't yet look at the changes to confirm that). But the luatex code is failing on a very strict version check (rather than checking for feature compatibility). One might say it blindly assumes incompatibility. Below is code from the texlive 20240312 source tree:
C:
    /* make sure header and library version are consistent */
    const char* version = zlibVersion();
    if (strncmp(version, ZLIB_VERSION, 2))
    {
        lua_pushfstring(L, "zlib library version does not match - header: %s, library: %s", ZLIB_VERSION, version);
        lua_error(L);
    }

It gets the version of the current dynamically linked library (static linking with libz.a would not have this problem) from the zlibVersion() function in the library. Then it compares against the ZLIB_VERSION in the zlib.h header file it included at the time the above source code was compiled. It's possible the package you downloaded that included luatex (the tex-luatex package) was built on a system that had zlib.h with ZLIB_VERSION defined to 1.3.

That's the background regarding how this can happen.

The fix is to get a luatex program that matches the libz.so on your system. You can possibly download an updated package from a package repository (official FreeBSD package repo or one that someone else has built including one you could have internally), or to rebuld the print/tex-luatex port yourself.

Maybe in your case, the upstream FreeBSD repository had a tex-luatex package that just hadn't been rebuilt yet against the latest zlib in 14.0 (at that time). Sometimes it happens - the upstream package repositories need time to build all the packages - they are especially busy doing builds right around the time leading up to and shortly after an official base version release.

If you build the port yourself, it is recommended to use a clean build environment (the poudriere tool helps with that). Or you might want to remove the installed version of the package before building the port (in /usr/ports/print/tex-luatex if you have the ports tree installed and up to date).

I recently tried to build the port and ran into this zlib problem because I updated FreeBSD 13 to a newer version (13.2 -> 13.4). In that span, zlib was updated from 1.2.1 to 1.3, and the port build has some leakage where it used the installed luatex as part of the build process ('make stage'). It shouldn't use the installed luatex but use the one it built in its own working area. But that's a separate bug with the port. The workaround is to delete the existing port and continue the build (or what I did was just rename /usr/local/bin/luatex to /usr/local/bin/luatex.mv - then the port build finished just fine).
 
In reality a particular port might NOT need to be rebuilt because an updated library change may still be ABI / API compatible with the previously installed version of the shared library.
The FreeBSD base version of libz has introduced no symbol changes since 1.2.12. Look at lib/libz/Symbol.map in the FreeBSD base source tree. Usually the maintainers are pretty good about adding appropriate versioning when there are ABI changes that introduce new symbols or remove old ones. Because of that, the overly cautious checking in luatex could perhaps be relaxed. For instance, the check could be changed to be non-fatal. Maybe that's a reasonable modification for the FreeBSD version of the port (if not upstream since the upstream project has to support OS projects that may not be as careful about ABI compatibility).
 
Back
Top