Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Installers: hash-check the uv fallback script; fail closed on undigested Lemonade assets (#13189)

Daniel Haned21e48c0c26
diff --git a/install.sh b/install.sh
index 50553c60e48..6a9d084a089 100755
--- a/install.sh
+++ b/install.sh
@@ -3824,6 +3824,9 @@ _uv_version_ok() { # uv command, floor (defaults to UV_MIN_VERSION)
# ── uv from a pinned release ──
# Mirrors Install-UvFromRelease in install.ps1; bumping the version means bumping every hash (<asset>.sha256) and every _uv_pinned_wheel entry.
UV_PINNED_VERSION="0.12.1"
+# sha256 of astral's versioned install.sh for UV_PINNED_VERSION (the release's uv-installer.sh asset), checked before the
+# unpinned-host fallback runs it.
+UV_INSTALLER_SH_SHA256="d3f5412d38c99f9d024901843bf98206f0d2c6dbe64df40d0b740e2751ca62c1"
# Echoes the glibc minor version (the N in 2.N), or nothing when this is not a glibc host or the version cannot be read. "not musl" is not the same as "a glibc new enough to run the GNU build": astral's installer checks a minimum and drops to its musl-static archive below it, so a host we cannot positively confirm has to reach the fallback rather than take a binary that will not exec.
_uv_glibc_minor() {
@@ -4122,7 +4125,15 @@ if ! command -v uv >/dev/null 2>&1 || ! _uv_version_ok uv; then
# The versioned installer installs the same pinned release (and checks its per-asset sha256), not whatever is latest.
_uv_tmp=$(mktemp)
if download "https://astral.sh/uv/$UV_PINNED_VERSION/install.sh" "$_uv_tmp"; then
- run_maybe_quiet sh "$_uv_tmp" </dev/null || _uv_refreshed=false
+ # A host with no sha256 tool runs it as before; anything else must be the exact pinned script.
+ # A hasher that fails (sha256sum without awk) counts as no hasher, not as an exit under set -e.
+ _uv_inst_sum=$(_uv_sha256 "$_uv_tmp" 2>/dev/null) || _uv_inst_sum=""
+ if [ -n "$_uv_inst_sum" ] && [ "$_uv_inst_sum" != "$UV_INSTALLER_SH_SHA256" ]; then
+ substep "uv installer script failed its sha256 check; not running it"
+ _uv_refreshed=false
+ else
+ run_maybe_quiet sh "$_uv_tmp" </dev/null || _uv_refreshed=false
+ fi
else
_uv_refreshed=false
fi
diff --git a/scripts/update_lemonade_pins.py b/scripts/update_lemonade_pins.py
index e98d5702da4..80993128c1e 100644
--- a/scripts/update_lemonade_pins.py
+++ b/scripts/update_lemonade_pins.py
@@ -97,7 +97,10 @@ def updated_section(
raise RuntimeError(f"{section['repo']} {tag} has no {asset_name}.")
sha256, size = hasher(asset["browser_download_url"])
github_digest = asset.get("digest")
- if github_digest and github_digest != f"sha256:{sha256}":
+ # Fail closed: without GitHub's digest the hash proves only what this runner downloaded.
+ if not github_digest:
+ raise RuntimeError(f"{asset_name}: GitHub publishes no digest; refusing to pin it.")
+ if github_digest != f"sha256:{sha256}":
raise RuntimeError(
f"{asset_name} hashed to sha256:{sha256}, but GitHub publishes {github_digest}."
)
diff --git a/studio/setup.sh b/studio/setup.sh
index 3420537e10f..18a6332a91f 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -2629,6 +2629,8 @@ _setup_http_get_timed() {
# Only the four mainstream targets are pinned; the rest fall through to the existing path
# rather than risk a binary for the wrong triple.
_SETUP_UV_PINNED_VERSION="0.12.1"
+# sha256 of astral's versioned install.sh for that release; the fallback below runs only those exact bytes.
+_SETUP_UV_INSTALLER_SH_SHA256="d3f5412d38c99f9d024901843bf98206f0d2c6dbe64df40d0b740e2751ca62c1"
# Mirrors _uv_glibc_minor in install.sh: "not musl" is not the same as "a glibc new enough to
# run the GNU build", and astral drops to its musl-static archive below its floor.
@@ -2843,6 +2845,30 @@ https://github.com/astral-sh/uv/releases/download/$_SETUP_UV_PINNED_VERSION"
return "$_siup_rc"
}
+# Unpinned hosts: astral's versioned installer, run only if it is the exact pinned script (a host with no sha256 tool
+# runs it as before). Non-zero when it is not run or fails.
+_setup_uv_fallback_run() {
+ _suf_tmp=$(mktemp) || return 1
+ if ! _setup_http_get "https://astral.sh/uv/$_SETUP_UV_PINNED_VERSION/install.sh" > "$_suf_tmp"; then
+ rm -f "$_suf_tmp"
+ return 1
+ fi
+ _suf_sum=$(_setup_uv_sha256 "$_suf_tmp" 2>/dev/null) || _suf_sum=""
+ if [ -n "$_suf_sum" ] && [ "$_suf_sum" != "$_SETUP_UV_INSTALLER_SH_SHA256" ]; then
+ echo "uv installer script failed its sha256 check; not running it" >&2
+ rm -f "$_suf_tmp"
+ return 1
+ fi
+ if _is_verbose; then
+ sh "$_suf_tmp" </dev/null
+ else
+ sh "$_suf_tmp" </dev/null > /dev/null 2>&1
+ fi
+ _suf_rc=$?
+ rm -f "$_suf_tmp"
+ return "$_suf_rc"
+}
+
# astral's installer wrote a profile line for whichever destination it chose. This replaces that
# installer, so setup.sh run directly (local or Colab) has to do the same or the export above
# dies with this shell and every later run reinstalls uv. Both of astral's opt-outs apply, and
@@ -3173,10 +3199,8 @@ elif {
_SETUP_UV_PINNED_OK=false
if _setup_install_uv_pinned || { [ "$_SIUP_UNFETCHED" = true ] && _mirror_switch uvbin && _setup_install_uv_pinned; }; then
_SETUP_UV_PINNED_OK=true
- elif _is_verbose; then
- _setup_http_get "https://astral.sh/uv/$_SETUP_UV_PINNED_VERSION/install.sh" | sh
else
- _setup_http_get "https://astral.sh/uv/$_SETUP_UV_PINNED_VERSION/install.sh" | sh > /dev/null 2>&1
+ _setup_uv_fallback_run
fi
}; then
# Only for astral's installer, which writes to ~/.local/bin. The pinned path already put its
diff --git a/tests/sh/test_uv_fallback_installer_sha.sh b/tests/sh/test_uv_fallback_installer_sha.sh
new file mode 100755
index 00000000000..5f228f72531
--- /dev/null
+++ b/tests/sh/test_uv_fallback_installer_sha.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+#
+# Hosts without a pinned uv build fall back to astral's versioned installer script. It now runs
+# only when its sha256 matches the pinned script, so a swapped script is refused like a failed
+# download, and a host with no sha256 tool keeps the old behaviour.
+set -e
+
+SCRIPT_DIR=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
+. "$SCRIPT_DIR/_harness.sh"
+SETUP_SH="$SCRIPT_DIR/../../studio/setup.sh"
+INSTALL_SH="$SCRIPT_DIR/../../install.sh"
+
+WORK=$(mktemp -d)
+trap 'rm -rf "$WORK"' EXIT INT TERM
+
+HELPER=$(awk '
+ /^_setup_uv_sha256\(\) \{/ { grab = 1 }
+ /^_setup_uv_fallback_run\(\) \{/ { grab = 1 }
+ grab { print }
+ grab && /^}/ { grab = 0 }
+' "$SETUP_SH")
+
+# A fake installer that leaves a marker when it runs, served by a stubbed downloader.
+printf 'touch "%s/ran"\n' "$WORK" > "$WORK/installer.sh"
+if command -v sha256sum >/dev/null 2>&1; then
+ GOOD_SUM=$(sha256sum "$WORK/installer.sh" | awk '{print $1}')
+else
+ GOOD_SUM=$(shasum -a 256 "$WORK/installer.sh" | awk '{print $1}')
+fi
+
+_run_fallback() {
+ # $1 = pinned sha256, $2 = 1 to hide every sha256 tool
+ rm -f "$WORK/ran"
+ (
+ eval "$HELPER"
+ _setup_http_get() { cat "$WORK/installer.sh"; }
+ _is_verbose() { return 1; }
+ _SETUP_UV_PINNED_VERSION="0.0.0"
+ _SETUP_UV_INSTALLER_SH_SHA256="$1"
+ if [ "$2" = 1 ]; then
+ _setup_uv_sha256() { :; }
+ elif [ "$2" = 2 ]; then
+ # sha256sum present but awk missing: the pipeline fails, under set -e as setup.sh runs.
+ set -e
+ _setup_uv_sha256() { return 127; }
+ fi
+ _setup_uv_fallback_run
+ ) 2>"$WORK/err"
+}
+
+if _run_fallback "$GOOD_SUM" 0 && [ -f "$WORK/ran" ]; then
+ ok "the pinned installer script runs"
+else
+ bad "the pinned installer script runs"
+fi
+
+if ! _run_fallback "0000000000000000000000000000000000000000000000000000000000000000" 0 && [ ! -f "$WORK/ran" ]; then
+ ok "a script with a different sha256 is refused and never runs"
+else
+ bad "a script with a different sha256 is refused and never runs"
+fi
+assert_contains "the refusal says why" "$(cat "$WORK/err")" "failed its sha256 check"
+
+if _run_fallback "0000000000000000000000000000000000000000000000000000000000000000" 1 && [ -f "$WORK/ran" ]; then
+ ok "a host with no sha256 tool runs it as before"
+else
+ bad "a host with no sha256 tool runs it as before"
+fi
+
+if _run_fallback "0000000000000000000000000000000000000000000000000000000000000000" 2 && [ -f "$WORK/ran" ]; then
+ ok "a hasher that fails counts as no hasher instead of aborting under set -e"
+else
+ bad "a hasher that fails counts as no hasher instead of aborting under set -e"
+fi
+
+_setup_pin=$(sed -n 's/^_SETUP_UV_INSTALLER_SH_SHA256="\([0-9a-f]*\)"$/\1/p' "$SETUP_SH")
+_install_pin=$(sed -n 's/^UV_INSTALLER_SH_SHA256="\([0-9a-f]*\)"$/\1/p' "$INSTALL_SH")
+if [ -n "$_setup_pin" ] && [ "$_setup_pin" = "$_install_pin" ]; then
+ ok "install.sh and setup.sh pin the same installer script"
+else
+ bad "install.sh and setup.sh pin the same installer script"
+fi
+
+# install.sh checks the digest before its run_maybe_quiet sh line.
+_check=$(grep -n 'UV_INSTALLER_SH_SHA256"' "$INSTALL_SH" | grep -v '^[0-9]*:UV_INSTALLER' | head -1 | cut -d: -f1)
+_run=$(grep -n 'run_maybe_quiet sh "\$_uv_tmp"' "$INSTALL_SH" | head -1 | cut -d: -f1)
+if [ -n "$_check" ] && [ -n "$_run" ] && [ "$_check" -lt "$_run" ]; then
+ ok "install.sh checks the installer digest before running it"
+else
+ bad "install.sh checks the installer digest before running it"
+fi
+
+echo ""
+echo " PASS: $PASS"
+echo " FAIL: $FAIL"
+if [ "$FAIL" -gt 0 ]; then
+ echo "FAILED"
+ exit 1
+fi
+echo "ALL PASSED"
diff --git a/tests/studio/install/test_update_lemonade_pins.py b/tests/studio/install/test_update_lemonade_pins.py
index 5d2e86d659a..c55ec75759e 100644
--- a/tests/studio/install/test_update_lemonade_pins.py
+++ b/tests/studio/install/test_update_lemonade_pins.py
@@ -96,6 +96,13 @@ def test_a_digest_mismatch_is_refused():
up.update_pins(lp.load_pins(), releases, _hasher)
+def test_an_asset_without_a_published_digest_is_refused():
+ name = "fastflowlm_99.0.1_linux.tar.gz"
+ releases = _releases("v1.0.0", "v99.0.1", **{name: {"digest": None}})
+ with pytest.raises(RuntimeError, match = "publishes no digest"):
+ up.update_pins(lp.load_pins(), releases, _hasher)
+
+
def test_a_release_missing_an_asset_is_refused():
release = _release("v99.0.1", {"linux-x64": "fastflowlm_99.0.1_linux.tar.gz"})
releases = {"lemonade-sdk/lemonade": {"tag_name": "v1.0.0", "assets": []}}