Skip to content

Studio: avoid AppImage COLRv1 font crashes - #9473

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
wasimysaid:fix/appimage-colrv1-runtime-9453
Aug 22, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
wasimysaid:fix/appimage-colrv1-runtime-9453

Conversation

@wasimysaid

@wasimysaid wasimysaid commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • bundle a known CBDT Noto emoji font only in the Linux AppImage
  • give that bundled file a private Fontconfig family and prefer it for glyphs it covers
  • keep normal host fonts available while preventing Jammy WebKitGTK/Skia from selecting host COLRv1 emoji fonts
  • verify the safe font, license, policy, and AppRun wiring in the complete-AppImage contract

Why

The fat AppImage bundles Ubuntu 22.04 WebKitGTK/Skia but intentionally uses the host FreeType runtime. On systems where Fontconfig selects a COLRv1 emoji font, this combination can abort in colrv1_configure_skpaint with std::vector::operator[]: Assertion '__n < this->size()' failed. Model Hub cards are one trigger.

Bundling an older FreeType made font rendering hang, and README-only sanitization does not cover every renderer path. The AppImage-scoped CBDT fallback avoids the incompatible COLRv1 path without changing .deb behavior or hiding README content.

Verification

  • 15 passed: tests/security/test_release_desktop_appimage.py
  • exact released v0.1.801 AppImage + pinned Noto COLRv1 font: FAIL, renderer session deleted and colrv1_configure_skpaint assertion observed
  • same v0.1.801 payload repacked with this runtime policy + same font/probe: PASS, Model Hub survived 30s and the explicit emoji/flag renderer probe survived 10s, no crash assertion
  • exact built-head negative: U+1FAEA is absent from the bundled CBDT font, so fda1fa05 selected the hostile host Noto-COLRv1.ttf; 61cb9f758 keeps the vetted bundled font and rejects every other color=true font, removing that fallback path
  • PR-head GitHub Actions: PASS on 61cb9f758 — run 32497188126 built the AppImage, proved the host selected the exact digest-pinned COLRv1 fixture for both U+1F680 and uncovered U+1FAEA, kept /hub alive for 30s while rendering the probe, and passed Ubuntu 22.04, Ubuntu 22.04 without GLES, Ubuntu 24.04 Wayland, Debian 12, and Fedora 44 portability lanes
  • independent review found one host-launcher environment leak; fda1fa05 scrubs FONTCONFIG_FILE before opening host browsers/file managers, with a focused Rust regression test
  • Codex found the uncovered-glyph fallback; fixed in 61cb9f758, re-reviewed on that exact head, and approved with no remaining major issues

Closes #9453.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 61cb9f7582

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 21, 2026
@oobabooga oobabooga self-assigned this Aug 21, 2026
@oobabooga

Copy link
Copy Markdown
Member

I added three follow-up commits after reproducing two gaps in the original policy.

  1. Fontconfig 2.13 path handling

    On Ubuntu 22.04, prefix="relative" resolved the bundled font directory as /share/unsloth/fonts. The policy rejected the host color font but never found its CBDT replacement, so U+1F680 fell through to DejaVu Sans.

    The launcher now materializes an AppDir-specific absolute policy. The bundled font is explicitly accepted, emoji and und-zsye requests prefer it, and normal text families use it only as a weak fallback.

  2. Live font-selection verification

    I exercised the corrected policy on:

    • Ubuntu 22.04 with Fontconfig 2.13.1
    • Ubuntu 24.04 with Fontconfig 2.15.0

    Both selected UnslothSafeEmoji.ttf for U+1F680 and explicit emoji requests, retained DejaVu Sans for U+0041 and generic text, and excluded the digest-pinned hostile COLRv1 fixture. An uncovered newer glyph could not fall back to that hostile font.

  3. Policy lifecycle

    The first follow-up still used age-based cleanup. I reproduced a second launch deleting the aged policy of a live first instance, leaving its next helper unable to load the config.

    Cleanup now checks whether the corresponding AppDir mount still exists. The live reproduction then preserved the aged active policy, removed the departed mount's policy, created the later instance's policy, kept the bundled emoji font selected, and continued rejecting the hostile font.

The final follow-up only shortens comments. The focused AppImage contract suite passes with 17 tests, and shell syntax and diff checks also pass.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9f53ae674

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +21 to +24
unsloth_fonts_appdir="$(printf '%s' "$APPDIR" | sed \
-e 's,&,\&amp;,g' -e 's,<,\&lt;,g' -e 's,>,\&gt;,g' \
-e 's,\\,\\\\,g' -e 's,&,\\&,g' -e 's,|,\\|,g')" &&
sed "s|@APPDIR@|$unsloth_fonts_appdir|g" "$unsloth_fonts_template" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Encode newlines before interpolating the mount path

When the AppImage filename’s unsanitized mount prefix, or an extracted AppDir name, contains a newline, command substitution preserves that newline and line 24 inserts it directly into the sed program, causing sed to fail with an unterminated substitution. Fresh evidence on the current tree: launching from an AppDir named abc\ndef leaves the materialized file empty and exports the shipped template instead, whose literal @APPDIR@ cannot locate UnslothSafeEmoji.ttf; emoji requests therefore lose the bundled safe renderer. Encode XML-invalid/control characters or avoid constructing a sed program from the path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced, but this lands on the designed fallback rather than on a defect, so I am leaving it.

An AppDir named abc\ndef does fail the substitution and export the shipped template, as you describe, and the truncated write leaves an empty policy behind. That empty file is removed by the next successful launch's cleanup, so it does not accumulate.

The template is not an absence of protection. Under it, fc-match 'sans-serif:charset=1f680' returns NotoSans-Regular.ttf with color=False; with no policy at all the same query returns NotoColorEmoji.ttf with color=True. The color=true rejectfont still runs, so host COLRv1 fonts stay out of the font set and the colrv1_configure_skpaint abort this PR exists to prevent does not return. What is lost is emoji glyphs, which is the tradeoff test_apprun_falls_back_to_the_shipped_font_policy_when_it_cannot_write already covers.

That is the difference from your previous item, which I agreed with and fixed. There a < in the mount path produced a malformed policy, Fontconfig logged Cannot load config file, discarded it and fell back to the host default, which put the crashing font back in front of Skia. A newline degrades safely; & and < did not.

The remaining gap is a file name no user produces. R&D.AppImage is a name people actually type, which is why the encoding change was worth making. Reaching this one means deliberately creating a file whose name contains a newline, and the payoff would be emoji glyphs in a session that is already running with the safe policy.

@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9f53ae674

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +21 to +23
unsloth_fonts_appdir="$(printf '%s' "$APPDIR" | sed \
-e 's,&,\&amp;,g' -e 's,<,\&lt;,g' -e 's,>,\&gt;,g' \
-e 's,\\,\\\\,g' -e 's,&,\\&,g' -e 's,|,\\|,g')" &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject XML-illegal bytes before selecting the generated policy

When the AppDir path contains an XML 1.0-illegal control byte such as U+0001—which Linux filenames permit and the AppImage mount prefix can inherit—these substitutions leave it unchanged; sed still succeeds, so FONTCONFIG_FILE points at the malformed output rather than taking the fallback. Fontconfig then reports that it cannot load the configuration and resumes selecting host fonts, re-exposing the COLRv1 crash this policy is meant to prevent. Fresh evidence on the current commit is that an AppDir named mount-a\x01b produces a materialized file containing that byte and fc-match rejects the file, so validate the generated policy or reject such paths before selecting it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reproduction is right, and it is worse than the newline case: here sed succeeds, so the malformed file is selected, Fontconfig reports Cannot load config file, and fc-match 'sans-serif:charset=1f680' returns the host NotoColorEmoji.ttf with color=True. The protection is gone, not degraded. I still do not think this should change the code, for two reasons.

First, the guard you describe cannot be made complete at this layer. A control byte is not the only byte the document cannot carry: an AppDir named mount-c\xFFd is an invalid UTF-8 sequence, not a control character, and it produces the identical outcome, not well-formed (invalid token) on the same line, policy discarded, host color font selected. So rejecting [[:cntrl:]] closes half a class and leaves the other half with the same consequence.

Second, closing the whole class means requiring the mount path to be representable in XML, and the only cheap way to test that is a byte whitelist. That has a real cost: an AppDir named mount-josé-Ünslöth-日本 works correctly today and selects the bundled font, and a whitelist strict enough to exclude a lone 0xFF would push those users onto the template fallback and silently cost them bundled emoji. Trading a regression for real paths against a byte no download, release pipeline or file manager produces is the wrong trade. Fontconfig needs the literal directory inside an XML document, so a path that cannot be represented there cannot be used; detecting that reliably needs a parser at launch, which is not worth adding to AppRun.

Where I did agree was the earlier item, and the distinction is reachability, not consequence. R&D.AppImage is a name people actually type, which is why & and < were worth encoding. A file name carrying 0x01 or a lone 0xFF has to be constructed deliberately.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 22, 2026
@oobabooga

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: c9f53ae674

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed there is no font policy in studio/src-tauri/linux/appimage-apprun.sh today, so the Model Hub freeze from the Skia colrv1_configure_skpaint abort is still reachable on a normal AppImage launch. Will get this reviewed.

@danielhanchen
danielhanchen merged commit 98a805b into unslothai:main Aug 22, 2026
52 of 54 checks passed
danielhanchen added a commit that referenced this pull request Aug 22, 2026
…the job (#9530)

* Bound the backend pytest session so a wedged xdist worker cannot eat the job

--timeout=330 arms inside each xdist worker, so it never fires when the controller
is what is stuck. On the #9473 branch this step went silent at 95 percent for 36.8
minutes, three runs running, each burning the full 45 minute budget and reporting
cancelled, which reads exactly like ordinary concurrency supersession.

Wrap the session in coreutils timeout: SIGINT at 1500s so pytest dumps where it was
stuck, SIGKILL 60s later. Reproduced with a test that forks a child that never exits.
Unwrapped the run is silent forever and the per-test cap never fires. Wrapped it exits
124 through execnet safe_terminate -> workerpool.waitall, the controller blocked on
its workers.

* Tighten comments

---------

Co-authored-by: danielhanchen <[email protected]>
Xoshbin added a commit to Xoshbin/asyar that referenced this pull request Nov 3, 2026
* fix(linux): prevent AppImage crash on COLRv1 colour fonts

The Linux AppImage is built on ubuntu-22.04, so the bundled WebKitGTK and
Skia are compiled against FreeType 2.11.1 headers. libfreetype.so.6 is not
bundled, so the host's FreeType is loaded at runtime. FreeType 2.13.0 added
a field to FT_ColorStopIterator, growing the struct from 16 to 20 bytes.

On hosts with FreeType >= 2.13 whose Fontconfig selects a COLRv1 colour
font, the layout mismatch corrupts colour-stop index arithmetic in Skia's
COLRv1 renderer:

  stl_vector.h:1123: colrv1_configure_skpaint(...)::ColorStop:
  Assertion '__n < this->size()' failed.

WebKitWebProcess then aborts (SIGABRT). The parent process survives and the
window is created but never painted, so the app appears as a black,
unresponsive window.

Write an AppImage-only Fontconfig file that rejects COLRv1 fonts and point
FONTCONFIG_FILE at it before the webview is created. Hosts fall back to a
CBDT/sbix emoji font, which never enters the COLRv1 code path.

Scoped to the AppImage on purpose: .deb/.rpm bundles link the host
WebKitGTK, which matches the host FreeType, so they cannot hit this.

Skipped when FONTCONFIG_FILE is already set by the user, and can be
disabled with ASYAR_ALLOW_HOST_COLRV1=1. Follows the existing pattern of
apply_linux_webkit_dmabuf_workaround().

Refs:
- block/buzz#2982
- Niko1221/Strata#4533
- unslothai/unsloth#9473
- #692 (same class of Linux AppImage packaging fix)

* fix(linux): harden AppImage COLRv1 fontconfig workaround

Resolve the host fonts.conf from FONTCONFIG_PATH or standard locations
instead of hardcoding /etc/fonts, skip the workaround when none exists,
ignore empty/relative XDG_CACHE_HOME, and write the config atomically.

* fix(linux): resolve relative FONTCONFIG_PATH and key COLRv1 config by contents

---------

Co-authored-by: Xoshbin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unsloth Desktop-0_1_801_beta linux appimage freeze

3 participants