From 465b1c476f83b30041524d5ae9f957d11141956d Mon Sep 17 00:00:00 2001 From: Md Zahangir Alam Date: Tue, 1 Dec 2026 16:58:35 -0500 Subject: [PATCH] fix(r): stop R plots emitting a Fontconfig error into the caller's stderr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every R job that drew text returned "Fontconfig error: Cannot load default config file" alongside its real output. NsJail mounts /usr but not /etc — api/config/sandbox.cfg has exactly two /etc entries, ld.so.cache and an inline hosts file — so fontconfig cannot reach /etc/fonts/fonts.conf. The fonts themselves were never missing: they live in /usr/share/fonts, which is mounted. Fixed by carrying fonts.conf into the R tree, which is already mounted, and pointing FONTCONFIG_FILE at it, rather than by adding /etc/fonts to the jail's mount set. Widening what an untrusted-code jail can see is not worth doing for a config file. The copy is self-sufficient: every it names is under /usr, and its only is conf.d with ignore_missing="yes". Same shape as the /usr/bin/which fix already in api/Dockerfile. Cosmetic only. Verified against sandbox-microvm:v1.11.0-6cdfe0c through /api/v2/execute, with and without the change as a control: the warning disappears and rendering is byte-identical — same text metrics, same PNG md5 376cf616d8d64863d3346d9e7559407f. The remaining "Error parsing /proc/self/maps" is pre-existing and unrelated. build-packages.sh gets the same treatment to keep local builds faithful; its Rscript wrapper was also missing the LD_LIBRARY_PATH export that package-init.sh has had since the launcher fix, so that divergence closes here. --- build-packages.sh | 13 +++++++++++++ docker/package-init.sh | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/build-packages.sh b/build-packages.sh index dbd0f9c0..3307d496 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -592,6 +592,8 @@ install_r() { cat > \"\$rscript\" << 'RSCRIPT' #!/bin/bash R_BIN=\"${pkg_dest}/bin/R\" +export LD_LIBRARY_PATH=\"${pkg_dest}/lib/R/lib:${pkg_dest}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}\" +export FONTCONFIG_FILE=\"\${FONTCONFIG_FILE:-${pkg_dest}/fontconfig/fonts.conf}\" if [ \"\$#\" -eq 0 ] || [ \"\${1#-}\" != \"\$1\" ]; then exec \"\$R_BIN\" --no-echo --no-restore \"\$@\" fi @@ -659,12 +661,22 @@ RINSTALL } EOF + # NsJail mounts /usr but not /etc, so fontconfig cannot find + # /etc/fonts/fonts.conf and every R plot that draws text warns. The + # fonts are fine — they live under /usr/share/fonts. Carry the config + # into the R tree, which is mounted. + if [ -r /etc/fonts/fonts.conf ]; then + mkdir -p ${pkg_dest}/fontconfig + cp /etc/fonts/fonts.conf ${pkg_dest}/fontconfig/fonts.conf + fi + cat > ${pkg_dest}/run << 'EOF' #!/bin/bash SCRIPT_DIR=\"\$(cd \"\$(dirname \"\${BASH_SOURCE[0]}\")\" && pwd)\" export R_HOME=\"\${SCRIPT_DIR}/lib/R\" export R_LIBS_SITE=\"\${SCRIPT_DIR}/lib/R/site-library\" export LD_LIBRARY_PATH=\"\${SCRIPT_DIR}/lib/R/lib:\${SCRIPT_DIR}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}\" +export FONTCONFIG_FILE=\"\${FONTCONFIG_FILE:-\${SCRIPT_DIR}/fontconfig/fonts.conf}\" exec \"\${SCRIPT_DIR}/bin/Rscript\" \"\$@\" EOF chmod +x ${pkg_dest}/run @@ -674,6 +686,7 @@ EOF echo 'R_HOME=${pkg_dest}/lib/R' echo 'LD_LIBRARY_PATH=${pkg_dest}/lib/R/lib:${pkg_dest}/syslib' echo 'R_LIBS_SITE=${pkg_dest}/lib/R/site-library' + echo 'FONTCONFIG_FILE=${pkg_dest}/fontconfig/fonts.conf' } > ${pkg_dest}/.env echo \$(date +%s)000 > ${pkg_dest}/.package-installed diff --git a/docker/package-init.sh b/docker/package-init.sh index 25f925ef..d7b28e60 100644 --- a/docker/package-init.sh +++ b/docker/package-init.sh @@ -671,6 +671,7 @@ R_BIN="${R_DEST}/bin/R" # Same reasoning as the run launcher: package build scripts call this directly # through R_HOME, where no .env has been applied. export LD_LIBRARY_PATH="${R_DEST}/lib/R/lib:${R_DEST}/syslib\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH}" +export FONTCONFIG_FILE="\${FONTCONFIG_FILE:-${R_DEST}/fontconfig/fonts.conf}" if [ "\$#" -eq 0 ] || [ "\${1#-}" != "\$1" ]; then # No file argument, or a flag such as -e: hand through unchanged. exec "\$R_BIN" --no-echo --no-restore "\$@" @@ -794,6 +795,26 @@ if [ -n "$R_ARCH" ] && [ "$INSTALL_FAILED" != true ]; then echo "Carried $(ls -1 "${R_DEST}/syslib" | wc -l) shared libraries into ${R_DEST}/syslib" rm -f /tmp/r-syslibs.txt + # Fontconfig's config lives at /etc/fonts/fonts.conf, and NsJail mounts + # /usr but NOT /etc — see api/config/sandbox.cfg, whose only /etc entries + # are ld.so.cache and an inline hosts file. So every R plot that draws text + # emitted "Fontconfig error: Cannot load default config file" into the + # caller's stderr. The fonts themselves were never the problem: they are in + # /usr/share/fonts, which IS mounted. + # + # Carried into the R tree rather than fixed by mounting /etc/fonts, because + # /pkgs/r/ is already mounted and widening the jail's mount set is + # not worth doing for a config file. The copy is self-sufficient: the dirs + # it names are under /usr, and its only include is conf.d with + # ignore_missing="yes". + if [ -r /etc/fonts/fonts.conf ]; then + mkdir -p "${R_DEST}/fontconfig" + cp /etc/fonts/fonts.conf "${R_DEST}/fontconfig/fonts.conf" + echo "Carried fonts.conf into ${R_DEST}/fontconfig" + else + echo "WARNING: /etc/fonts/fonts.conf not found; R plots will warn about fontconfig" + fi + cat > "$R_DEST/pkg-info.json" << EOF { "language": "r", @@ -819,6 +840,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" export R_HOME="${SCRIPT_DIR}/lib/R" export R_LIBS_SITE="${SCRIPT_DIR}/lib/R/site-library" export LD_LIBRARY_PATH="${SCRIPT_DIR}/lib/R/lib:${SCRIPT_DIR}/syslib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" +export FONTCONFIG_FILE="${FONTCONFIG_FILE:-${SCRIPT_DIR}/fontconfig/fonts.conf}" exec "${SCRIPT_DIR}/bin/Rscript" "$@" EOF chmod +x "$R_DEST/run" @@ -832,6 +854,7 @@ EOF echo "R_HOME=${R_DEST}/lib/R" echo "LD_LIBRARY_PATH=${R_DEST}/lib/R/lib:${R_DEST}/syslib" echo "R_LIBS_SITE=${R_DEST}/lib/R/site-library" + echo "FONTCONFIG_FILE=${R_DEST}/fontconfig/fonts.conf" } > "$R_DEST/.env" echo "$(date +%s)000" > "$R_DEST/.package-installed"