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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Unpack the mirrored uv wheel with python3 -m zipfile instead of an inline one-liner (#12194)
Daniel Han78e634c4217a
diff --git a/install.sh b/install.shindex 3262e9bed63..984e1dc3850 100755--- a/install.sh+++ b/install.sh@@ -3849,7 +3849,7 @@ _uv_unzip() {*bsdtar*) tar -xf "$1" -C "$2" 2>/dev/null && return 0 ;;esaccommand -v python3 >/dev/null 2>&1 &&- python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$1" "$2" 2>/dev/null+ python3 -m zipfile -e "$1" "$2" >/dev/null 2>&1}# Echoes the SHA-256 of "$1", or nothing when the host has no digest tool.diff --git a/scripts/lint_av_shapes.py b/scripts/lint_av_shapes.pyindex 6c5f0938c93..9d560a04016 100644--- a/scripts/lint_av_shapes.py+++ b/scripts/lint_av_shapes.py@@ -662,6 +662,29 @@ RULES = [r"(?i)\b(?:curl|wget)\b[^\n|]*\|\s*(?:sudo\s+)?(?:ba|z|da)?sh\b",],),+ Rule(+ "AV016",+ "error",+ "an inline interpreter one-liner unpacks an archive",+ "fetching an archive and unpacking it with a `-c` one-liner is the dropper shape; a vendor has scored "+ "install.sh as a downloader for exactly this line",+ "use the interpreter's own module entry point (python3 -m zipfile -e ARCHIVE DIR), unzip or tar",+ applies = lambda p: not p.endswith((".py", ".rs", ".js", ".mjs", ".cjs", ".ts", ".tsx")),+ needles = tuple(_J(p) for p in (("ext", "ract"), ("unpack_", "archive"))),+ # Options may take an argument (-W ignore) or be combined with the command flag (-Ic). The+ # call has to sit inside the quoted program (escaped quotes included, not a later command or+ # comment) after an archive name, so an HTML node's .extract() is not an archive.+ line_patterns = [+ r"(?i)\b(?:python[0-9.]*|py|node|perl|ruby)(?:\.exe)?"+ r"(?:\s+--?[\w-]+(?:\s+[^\s'\"-][^\s'\"]*)?)*?\s+-[a-z]*[ce]\s*(['\"])(?:\\.|(?!\1)[^\n])*?"+ + _any(+ r"(?:zip|tar|archive)(?:\\.|(?!\1)[^\n])*?(?:\.|->)"+ + _J(("ext", "ract"))+ + r"(?:all)?\s*\(",+ _J(("unpack_", "archive")),+ )+ ],+ ),]RULES_BY_ID = {rule.id: rule for rule in RULES}# PowerShell resolves commands, members and parameters in any case, and so do Windows paths.@@ -1031,6 +1054,112 @@ def _fixtures() -> list[tuple[str, str, str, bool]]:("AV014", "install.ps1", "# resolves the venv python before the first pip call", False),("AV015", "t.ps1", "$sb = [scriptblock]::Create($text)", True),("AV015", "t.ps1", ". $PSScriptRoot/helpers.ps1", False),+ (+ "AV016",+ "t.sh",+ "python3 -c 'import sys, zipfile; zipfile."+ + _J(("Zip", "File"))+ + "(sys.argv[1])."+ + _J(("extract", "all"))+ + '(sys.argv[2])\' "$1" "$2"',+ True,+ ),+ ("AV016", "t.sh", 'python3 -m zipfile -e "$1" "$2"', False),+ (+ "AV016",+ "t.sh",+ "python3 -c 'import zipfile; zipfile."+ + _J(("Zip", "File"))+ + "(a).extract("+ + '"uv")'+ + "'",+ True,+ ),+ (+ "AV016",+ "t.mjs",+ "const cmd = "+ + '"'+ + "python3 -c 'import zipfile; zipfile."+ + _J(("Zip", "File"))+ + "(a)."+ + _J(("extract", "all"))+ + "(b)'"+ + '"',+ False,+ ),+ # Options before the command flag, with an argument or combined with it.+ (+ "AV016",+ "t.sh",+ "python3 -W ignore -c 'import zipfile; zipfile.ZipFile(a)."+ + _J(("extract", "all"))+ + "(b)'",+ True,+ ),+ (+ "AV016",+ "t.sh",+ "python3 -Ic 'import tarfile; tarfile.open(a)." + _J(("extract", "all")) + "(b)'",+ True,+ ),+ (+ "AV016",+ "t.sh",+ "python3 -c 'import shutil; shutil." + _J(("unpack_", "archive")) + "(a, b)'",+ True,+ ),+ (+ "AV016",+ "t.sh",+ 'python3 -c "import zipfile; zipfile.ZipFile(\\"a.zip\\").'+ + _J(("extract", "all"))+ + '(\\"out\\")"',+ True,+ ),+ (+ "AV016",+ "t.sh",+ 'perl -e \'use Archive::Tar; Archive::Tar->new("a.tar")->'+ + _J(("ext", "ract"))+ + "()'",+ True,+ ),+ (+ "AV016",+ "t.sh",+ "python3 -c 'from bs4 import BeautifulSoup; BeautifulSoup(x).div."+ + _J(("ext", "ract"))+ + "()'",+ False,+ ),+ # Reading or checking an archive unpacks nothing.+ (+ "AV016",+ "t.sh",+ "python3 -c 'print(1)' # a later archive."+ + _J(("ext", "ract"))+ + "() call is not this one",+ False,+ ),+ (+ "AV016",+ "t.sh",+ "python3 -c 'import sys, zipfile; print(zipfile.is_zipfile(sys.argv[1]))' \"$f\"",+ False,+ ),+ (+ "AV016",+ "t.sh",+ "python3 -c 'import zipfile; print(zipfile.ZipFile(a).namelist())'",+ False,+ ),+ (+ "AV016",+ "t.py",+ "zipfile." + _J(("Zip", "File")) + "(path)." + _J(("extract", "all")) + "(dest)",+ False,+ ),# Spellings PowerShell accepts that a first cut of these rules missed.("AV002",diff --git a/studio/setup.sh b/studio/setup.shindex 7b75b116a30..bec88be2052 100755--- a/studio/setup.sh+++ b/studio/setup.sh@@ -2601,7 +2601,7 @@ _setup_uv_unzip() {*bsdtar*) tar -xf "$1" -C "$2" 2>/dev/null && return 0 ;;esaccommand -v python3 >/dev/null 2>&1 &&- python3 -c 'import sys, zipfile; zipfile.ZipFile(sys.argv[1]).extractall(sys.argv[2])' "$1" "$2" 2>/dev/null+ python3 -m zipfile -e "$1" "$2" >/dev/null 2>&1}_setup_uv_sha256() {diff --git a/tests/security/test_lint_av_shapes.py b/tests/security/test_lint_av_shapes.pyindex b419dd567cf..ecece5c4a6c 100644--- a/tests/security/test_lint_av_shapes.py+++ b/tests/security/test_lint_av_shapes.py@@ -131,6 +131,7 @@ INCIDENTS = [("268b771b9", None, "tests/studio/install/test_keep_install_backcompat_9979.py", "AV009"),("268b771b9", None, "tests/security/test_release_desktop_signing_simulation.py", "AV009"),("268b771b9", None, "tests/studio/test_install_rollback_lifecycle.ps1", "AV010"),+ ("8c8dd864c", None, "install.sh", "AV016"),]diff --git a/tests/sh/test_uv_pinned_release.sh b/tests/sh/test_uv_pinned_release.shindex 6850d133f84..6bb74e6865e 100755--- a/tests/sh/test_uv_pinned_release.sh+++ b/tests/sh/test_uv_pinned_release.sh@@ -1123,14 +1123,17 @@ _pa=$(grep -n '^_SETUP_PROBE_TARGET=' "$SETUP_SH" | cut -d: -f1)_pb=$(awk -v s="$(grep -n '^_setup_probe_version() {' "$SETUP_SH" | cut -d: -f1)" 'NR > s && /^}$/ { print NR; exit }' "$SETUP_SH"){ sed -n "${_pa},${_pb}p" "$SETUP_SH"; sed -n "${_sa},${_sb}p" "$SETUP_SH"; } > "$WORK/uvfns_setup.sh"cp "$WORK/uvfns.sh" "$WORK/uvfns_install.sh"-for _run in install:good install:bad setup:good setup:bad; do- _wh="$WORK/wheel_${_run%:*}_${_run#*:}"; mkdir -p "$_wh"; _want=$WHEEL_SHA; [ "${_run#*:}" = good ] || _want=$(printf '0%.0s' $(seq 64))+# A :py run hides unzip too, so the python3 zipfile fallback does the extraction.+for _run in install:good install:bad setup:good setup:bad install:good:py setup:good:py; do+ _py=${_run#*:*:}; [ "$_py" != "$_run" ] || _py=""; _run=${_run%:py}+ _wh="$WORK/wheel_${_run%:*}_${_run#*:}${_py:+_py}"; mkdir -p "$_wh"; _want=$WHEEL_SHA; [ "${_run#*:}" = good ] || _want=$(printf '0%.0s' $(seq 64))(set +e; tauri_log() { :; }# shellcheck disable=SC1090. "$WORK/uvfns_${_run%:*}.sh"# GNU tar cannot read a zip; stand in for it where tar is bsdtar, which can.tar() { case "$*" in *.whl*) return 1 ;; esac; command tar "$@"; }+ [ -z "$_py" ] || unzip() { return 1; }_uv_pinned_asset() { echo "uv-fake.tar.gz $FIXTURE_SHA"; }; _setup_uv_pinned_asset() { _uv_pinned_asset; }_uv_pinned_wheel() { echo "packages/ab/cd/uv-fake.whl $_want"; }; _setup_uv_pinned_wheel() { _uv_pinned_wheel; }download() { echo "$1" >> "$_wh.get"; cp -f "$WORK/uv-fake.whl" "$2"; }; _setup_http_get() { download "$1" /dev/stdout; }; _setup_persist_uv_path() { :; }@@ -1141,7 +1144,7 @@ for _run in install:good install:bad setup:good setup:bad; do_got=no; [ -x "$_wh/.local/bin/uv" ] && [ -x "$_wh/.local/bin/uvx" ] \&& [ "$(cat "$_wh.get")" = "https://mirror.example/pypi/web/packages/ab/cd/uv-fake.whl" ] && _got=yes_exp=no; [ "${_run#*:}" = good ] && _exp=yes- assert_eq "$_run: wheel-mirror install (good digest installs from the mirror only, bad installs nothing)" "$_exp" "$_got"+ assert_eq "$_run${_py:+ (python3 zipfile)}: wheel-mirror install (good digest installs from the mirror only, bad installs nothing)" "$_exp" "$_got"done_wheels() { grep -oE 'uv-[0-9.]+-py3-none-[a-z0-9_.]+\.whl [0-9a-f]{64}"' "$1" | sort; }assert_eq "install.sh and setup.sh pin the same four wheels of the pinned uv" "4 $(_wheels "$INSTALL_SH")" \