From 11ddbf76b3d58a260dc22a90266d2cf6ffd2a6f7 Mon Sep 17 00:00:00 2001 From: cunoe Date: Thu, 12 Nov 2026 22:14:08 -0800 Subject: [PATCH 1/5] fix(update): find releases through tag refs instead of the full listing The updater downloaded every page of the release listing before choosing a version. Each product release now attaches about 45 assets, so the first page already returns 2.2 MiB and would pass the 4 MiB response limit after about 30 more product releases, failing every check and apply. List the product tag refs instead (one small response), keep the channel's tags newer than the running version in numeric order, and fetch only those releases, newest first. A missing or draft release answers 404 and is skipped; everything after that keeps the existing verification. Probing is capped at 16 candidates and reports an error instead of 'no update' when none of them is complete. --- apps/cli/src/update/release.rs | 135 +++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 30 deletions(-) diff --git a/apps/cli/src/update/release.rs b/apps/cli/src/update/release.rs index c65e64b2..940573fe 100644 --- a/apps/cli/src/update/release.rs +++ b/apps/cli/src/update/release.rs @@ -18,7 +18,8 @@ use vibeface_bridge::platform::privatefs; use vibeface_control::{DATA_EPOCH, UPDATE_PROTOCOL}; const API: &str = "https://api.github.com/repos/leaperone/vibeface"; -const MAX_PAGES: usize = 20; +/// Releases fetched one by one, newest first, before discovery gives up on finding a complete one. +const MAX_CANDIDATES: usize = 16; const MAX_JSON: u64 = 4 * 1024 * 1024; const MAX_ARCHIVE: u64 = 128 * 1024 * 1024; const MAX_UNPACKED: u64 = 512 * 1024 * 1024; @@ -83,39 +84,59 @@ struct ObjectResponse { object: GitObject, } +#[derive(Deserialize)] +struct TagRef { + #[serde(rename = "ref")] + name: String, +} + /// Find a newer official release in the selected channel without running providers. +/// +/// Every product release attaches dozens of assets, so the full release listing outgrows any +/// response limit. Tag refs stay small: list them, order the channel's tags by version and fetch +/// only the newer releases, newest first, until one is complete. pub async fn check(channel: Channel) -> Result> { let client = client()?; let current = Version::parse(env!("CARGO_PKG_VERSION"))?; - let mut candidates: Vec<(Version, GithubRelease)> = Vec::new(); - for page in 1..=MAX_PAGES { - let releases: Vec = - get_json(&client, &format!("{API}/releases?per_page=100&page={page}")).await?; - let complete = releases.len() < 100; - for release in releases { - let Some(version) = channel_version(&release.tag_name, channel) else { - continue; - }; - if release.draft - || release.prerelease != (channel == Channel::Nightly) - || version <= current - { - continue; - } - candidates.push((version, release)); + let refs: Vec = get_json(&client, &format!("{API}/git/matching-refs/tags/v")).await?; + let candidates = candidate_tags(&refs, channel, ¤t); + let bounded = candidates.len() > MAX_CANDIDATES; + for (version, tag) in candidates.into_iter().take(MAX_CANDIDATES) { + // Drafts and tags whose release has not been created yet answer 404. + let Some(release) = + get_optional_json::(&client, &format!("{API}/releases/tags/{tag}")) + .await? + else { + continue; + }; + ensure!( + release.tag_name == tag, + "release lookup returned a different tag" + ); + if release.draft || release.prerelease != (channel == Channel::Nightly) { + continue; } - if complete { - candidates.sort_by(|a, b| b.0.cmp(&a.0)); - for (version, release) in candidates { - match resolve_release(&client, release, version).await? { - Some(release) => return Ok(Some(release)), - None => continue, - } - } - return Ok(None); + if let Some(release) = resolve_release(&client, release, version).await? { + return Ok(Some(release)); } } - bail!("release listing reached {MAX_PAGES} pages; cannot confirm a complete listing") + ensure!( + !bounded, + "none of the {MAX_CANDIDATES} newest candidate releases is complete; cannot confirm the latest release" + ); + Ok(None) +} + +/// The channel's tags newer than `current`, newest first. Other refs are ignored. +fn candidate_tags(refs: &[TagRef], channel: Channel, current: &Version) -> Vec<(Version, String)> { + let mut candidates: Vec<_> = refs + .iter() + .filter_map(|item| item.name.strip_prefix("refs/tags/")) + .filter_map(|tag| Some((channel_version(tag, channel)?, tag.to_owned()))) + .filter(|(version, _)| version > current) + .collect(); + candidates.sort_by(|a, b| b.0.cmp(&a.0)); + candidates } fn channel_version(tag: &str, channel: Channel) -> Option { @@ -197,7 +218,10 @@ async fn resolve_release( marker_asset.browser_download_url == manifest_url, "unexpected completion manifest URL" ); - let Some(body) = get_optional_bytes(client, &manifest_url, 1024 * 1024).await? else { + let Some(body) = get_optional_bytes(client, &manifest_url, 1024 * 1024) + .await + .context("fetch release completion manifest")? + else { return Ok(None); }; let manifest = parse_completion_manifest(&body, &release.tag_name, &version)?; @@ -417,6 +441,17 @@ async fn get_json(client: &Client, url: &str) -> .context("decode GitHub release response") } +/// Like [`get_json`], but a 404 is `None` instead of an error. +async fn get_optional_json( + client: &Client, + url: &str, +) -> Result> { + get_optional_bytes(client, url, MAX_JSON) + .await? + .map(|body| serde_json::from_slice(&body).context("decode GitHub release response")) + .transpose() +} + async fn response(client: &Client, url: &str) -> Result { let url = Url::parse(url)?; ensure!(trusted_url(&url), "update URL is not approved"); @@ -464,13 +499,13 @@ async fn get_optional_bytes(client: &Client, url: &str, limit: u64) -> Result = serde_json::from_value(serde_json::json!([ + {"ref": "refs/tags/v0.0.1-nightly.20261112.3", "object": {"sha": "a", "type": "commit"}}, + {"ref": "refs/tags/v0.0.1-nightly.20261112.10"}, + {"ref": "refs/tags/v0.0.1-nightly.20261113.1"}, + {"ref": "refs/tags/v0.0.1-nightly.20261101.1"}, + {"ref": "refs/tags/v0.0.1"}, + {"ref": "refs/tags/v0.0.2"}, + {"ref": "refs/tags/v0.0.2-rc.1"}, + {"ref": "refs/tags/www-v0.0.1-nightly.20261113.1"}, + {"ref": "refs/tags/cli-v0.0.9"}, + {"ref": "refs/heads/v0.0.3"}, + {"ref": "v0.0.4"} + ])) + .unwrap(); + let current = Version::parse("0.0.1-nightly.20261110.4").unwrap(); + let tags = |channel| { + candidate_tags(&refs, channel, ¤t) + .into_iter() + .map(|(version, tag)| { + assert_eq!(format!("v{version}"), tag); + tag + }) + .collect::>() + }; + // Numeric order, so .10 comes before .3, and only tags newer than the running version. + assert_eq!( + tags(Channel::Nightly), + [ + "v0.0.1-nightly.20261113.1", + "v0.0.1-nightly.20261112.10", + "v0.0.1-nightly.20261112.3" + ] + ); + assert_eq!(tags(Channel::Stable), ["v0.0.2", "v0.0.1"]); + let latest = Version::parse("0.0.2").unwrap(); + assert!(candidate_tags(&refs, Channel::Stable, &latest).is_empty()); + } + #[test] fn optional_unique_asset_distinguishes_missing_duplicate_and_unique() { let assets = [ From 75d62859c7d6d60bd841d2514174f6ffac79becc Mon Sep 17 00:00:00 2001 From: cunoe Date: Thu, 12 Nov 2026 22:27:47 -0800 Subject: [PATCH 2/5] fix(install): select releases through tag refs in both installers install.sh and install.ps1 read every page of the release listing with the same 4 MiB page limit as the updater, so they would stop installing at the same point. Both now list the product tag refs, order the channel's tags by version and look up those releases one at a time, newest first. A release that is missing, a draft or carries the wrong prerelease flag is skipped before its completion manifest is read; a lookup that answers for another tag fails. At most 16 candidates are looked up. The self-tests cover tag-ref parsing (including refs outside refs/tags and unsafe names), the three skip cases, the tag mismatch and the lookup bound on both sides of 16; the pagination-only cases are removed. The release notes describe the new discovery. --- install.sh | 178 ++++++++++++++++++++++++------------- packages/docs/releasing.md | 4 +- scripts/install.ps1 | 123 +++++++++++++++++-------- 3 files changed, 204 insertions(+), 101 deletions(-) diff --git a/install.sh b/install.sh index e117a3f7..0f8004dd 100755 --- a/install.sh +++ b/install.sh @@ -26,6 +26,11 @@ json_fields() { if (mode=="completion" && depth==1 && k !~ /^(app|version|tag|source_commit|channel|schema|assets)$/) error() if (mode=="completion" && depth==3 && k !~ /^(name|size|sha256)$/) error() if (mode=="completion" && k=="assets") { seen[0 SUBSEP k]++; return } + if (mode=="refs") { + if (k!="ref") return + if (value !~ /^"refs\/tags\//) error() + value="\"" substr(value,12); k="tag_name" + } if (!(k ~ /^(tag_name|draft|prerelease|sha|app|version|tag|channel|schema|name|size|sha256|target|source_commit|update_protocol|data_epoch|core_version|core_source_commit|app_version|app_source_commit)$/)) return record_key=(mode=="completion" && depth==1 ? 0 : record) if (seen[record_key SUBSEP k]++) error() @@ -38,7 +43,7 @@ json_fields() { } print page "." record_key "\t" k "\t" value } - BEGIN { depth=0; record=0; expected=(mode=="releases" ? "[" : "{") } + BEGIN { depth=0; record=0; expected=(mode=="refs" ? "[" : "{") } { json=$0 position=1; size=length(json) @@ -65,14 +70,14 @@ json_fields() { if (token !~ /^"/ && token !~ /^(-?[0-9]+([.][0-9]+)?([eE][+-]?[0-9]+)?|true|false|null|[][{}:,])$/) error() if (closed) error() if (!started++) { if (token!=expected) error() } - at=(mode=="releases" ? 2 : 1) + at=(mode=="refs" ? 2 : 1) if (key!="" && token!=":" && (depth==at || (mode=="completion" && depth==3))) { if (mode!="completion" || depth==1 || key ~ /^(name|size|sha256)$/) field(token) } if (token=="{" || token=="[") { if (depth==0 && closed) error() depth++; stack[depth]=token - if ((mode=="releases" && depth==2) || (mode=="completion" && depth==3)) { if (token!="{") error(); record++ } + if ((mode=="refs" && depth==2) || (mode=="completion" && depth==3)) { if (token!="{") error(); record++ } if (depth>64) error() } else if (token=="}" || token=="]") { if (depth<1 || (token=="}" ? stack[depth]!="{" : stack[depth]!="[")) error() @@ -86,7 +91,6 @@ json_fields() { } END { if (invalid || !started || depth || !closed || (mode=="completion" && !seen[0 SUBSEP "assets"])) exit 1 - if (mode=="releases") print record "\tcount\t" record } ' "$1" } @@ -103,11 +107,9 @@ select_release() { return y>0 && m>=1 && m<=12 && d>=1 && d<=days } $2=="tag_name" { tags[$1]=$3 } - $2=="draft" { draft[$1]=$3 } - $2=="prerelease" { pre[$1]=$3 } END { for (i in tags) { - tag=tags[i]; if (draft[i]!="false" || pre[i]!=(channel=="nightly" ? "true" : "false")) continue + tag=tags[i] if (substr(tag,1,1)!="v") continue n=split(substr(tag,2),part,"-"); if (n!=(channel=="nightly" ? 2 : 1)) continue if (split(part[1],base,".")!=3 || !number(base[1]) || !number(base[2]) || !number(base[3])) continue @@ -128,15 +130,16 @@ select_releases() { select_release "$1" "$2" all | awk '{line[NR]=$0} END {for(i=NR;i>0;i--) print line[i]}' } -fetch_optional_marker() { - local url="$1" destination="$2" code +# Returns 1 only for HTTP 404; any other failure stops the installation. +fetch_optional() { + local url="$1" destination="$2" limit="$3" label="$4" code code=$(curl --silent --show-error --location --proto '=https' --proto-redir '=https' --tlsv1.2 \ - --connect-timeout 15 --max-time 180 --max-filesize 1048576 -o "$destination" -w '%{http_code}' \ - --header 'Accept: application/vnd.github+json' --user-agent 'vibeface-installer' "$url") || fail "completion manifest transport failed: $url" + --connect-timeout 15 --max-time 180 --max-filesize "$limit" -o "$destination" -w '%{http_code}' \ + --header 'Accept: application/vnd.github+json' --user-agent 'vibeface-installer' "$url") || fail "$label transport failed: $url" case "$code" in - 200) [[ $(wc -c < "$destination") -le 1048576 ]] || fail 'completion manifest exceeds size limit'; return 0 ;; + 200) [[ $(wc -c < "$destination") -le $limit ]] || fail "$label exceeds size limit"; return 0 ;; 404) return 1 ;; - *) fail "completion manifest request failed with HTTP $code" ;; + *) fail "$label request failed with HTTP $code" ;; esac } @@ -276,30 +279,34 @@ install_release() ( rm -rf "$scratch" ' EXIT trap 'exit 130' INT TERM - local page count found=false - : > "$scratch/releases" - for ((page=1; page<=20; page++)); do - fetch "https://api.github.com/repos/leaperone/vibeface/releases?per_page=100&page=$page" "$scratch/page.json" 4194304 - json_fields "$scratch/page.json" releases "$page" > "$scratch/page-fields" || fail 'invalid GitHub release response' - cat "$scratch/page-fields" >> "$scratch/releases" - count=$(awk -F '\t' '$2=="count" {print $3}' "$scratch/page-fields") - if ((count < 100)); then found=true; break; fi - done - "$found" || fail 'release list exceeds 20 pages; cannot select the latest version safely' - local candidate manifest_fields selected=false + # The full release listing grows by every release's assets; tag refs stay small. Order the + # channel's tags by version, then look up only those releases, newest first. + fetch "https://api.github.com/repos/leaperone/vibeface/git/matching-refs/tags/v" "$scratch/refs.json" 4194304 + json_fields "$scratch/refs.json" refs > "$scratch/refs" || fail 'invalid GitHub tag response' + local candidate manifest_fields selected=false probed=0 prerelease=false + [[ $channel == stable ]] || prerelease=true while IFS= read -r candidate; do [[ -n $candidate ]] || continue + ((probed < 16)) || fail 'none of the 16 newest candidate releases is complete; cannot select the latest version safely' + probed=$((probed + 1)) + # Drafts and tags whose release has not been created yet answer 404. + fetch_optional "https://api.github.com/repos/leaperone/vibeface/releases/tags/$candidate" "$scratch/release-object.json" 4194304 'release lookup' || continue + json_fields "$scratch/release-object.json" object > "$scratch/release-fields" || fail 'invalid GitHub release response' + awk -F '\t' -v tag="$candidate" '$2=="tag_name" {name=$3} END {exit name!=tag}' "$scratch/release-fields" || + fail 'release lookup returned a different tag' + awk -F '\t' -v pre="$prerelease" '$2=="draft" {draft=$3} $2=="prerelease" {p=$3} END {exit !(draft=="false" && p==pre)}' \ + "$scratch/release-fields" || continue version=${candidate#v} package="vibeface-$version-$target" archive="$package.tar.gz" - if ! fetch_optional_marker "https://github.com/leaperone/vibeface/releases/download/$candidate/release.json" "$scratch/release.json"; then + if ! fetch_optional "https://github.com/leaperone/vibeface/releases/download/$candidate/release.json" "$scratch/release.json" 1048576 'completion manifest'; then continue fi manifest_fields=$(verify_completion "$scratch/release.json" "$candidate" "$version" "$target" "$archive") || fail 'release completion manifest validation failed' tag=$candidate selected=true break - done < <(select_releases "$scratch/releases" "$channel") + done < <(select_releases "$scratch/refs" "$channel") "$selected" || tag='' if [[ -z $tag ]]; then if [[ $channel == stable ]]; then fail 'no published Stable release; use --channel nightly explicitly to install a preview'; fi @@ -513,8 +520,18 @@ while (($#)); do esac done case "$url" in - *'/releases?per_page=100&page=1') cp "$VIBEFACE_INSTALL_FIXTURE/releases.json" "$output" ;; - *'/releases?per_page=100&page=2') cp "$VIBEFACE_INSTALL_FIXTURE/page2.json" "$output" ;; + *'/git/matching-refs/tags/v') cp "$VIBEFACE_INSTALL_FIXTURE/refs.json" "$output" ;; + */releases/tags/*) + tag=${url##*/releases/tags/} + rcode=404 + if [[ -f "$VIBEFACE_INSTALL_FIXTURE/release/$tag.json" ]]; then + rcode=200 + cp "$VIBEFACE_INSTALL_FIXTURE/release/$tag.json" "$output" + else + : > "$output" + fi + [[ ${writeout:-} != '%{http_code}' ]] || printf '%s' "$rcode" + exit 0 ;; *'/commits/'*) printf '{"sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","nested":{"sha":"ignored"}}' > "$output" ;; */releases/download/*/release.json) tag=${url#*://github.com/leaperone/vibeface/releases/download/} @@ -549,26 +566,51 @@ MOCK printf 'Linux\n' > "$fixture/os" printf 'x86_64\n' > "$fixture/arch" export PATH="$fixture/bin:$PATH" - cat > "$fixture/releases.json" <<'JSON' + # Each argument is TAG:DRAFT:PRERELEASE and publishes that release; a bare TAG has no release yet. + write_releases() { + local spec tag draft prerelease separator='' + rm -rf "$fixture/release" + mkdir -p "$fixture/release" + printf '[' > "$fixture/refs.json" + for spec in "$@"; do + IFS=: read -r tag draft prerelease <<< "$spec" + printf '%s{"ref":"refs/tags/%s","object":{"sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","type":"commit"}}' "$separator" "$tag" >> "$fixture/refs.json" + separator=, + [[ -z $draft ]] || printf '{"tag_name":"%s","name":"%s","draft":%s,"prerelease":%s,"body":"quoted \\"tag_name\\": \\"v999.0.0\\"","assets":[{"name":"ignored","size":1}]}\n' \ + "$tag" "$tag" "$draft" "$prerelease" > "$fixture/release/$tag.json" + done + printf ']\n' >> "$fixture/refs.json" + } + cat > "$fixture/refs.json" <<'JSON' [ - {"tag_name":"v0.0.1-nightly.20261017.2","draft":false,"prerelease":true,"body":"quoted \"tag_name\": \"v999.0.0\""}, - {"tag_name":"cli-v999.0.0","draft":false,"prerelease":false}, - {"tag_name":"www-v999.0.0-nightly.20261017.99","draft":false,"prerelease":true}, - {"tag_name":"mobile-v999.0.0-nightly.20261017.99","draft":false,"prerelease":true}, - {"tag_name":"v1.9.0","draft":false,"prerelease":false}, - {"tag_name":"v0.0.1-nightly.20261017.10","draft":false,"prerelease":true}, - {"tag_name":"v1.10.0","draft":false,"prerelease":false}, - {"tag_name":"v999.0.0-rc.1","draft":false,"prerelease":true}, - {"tag_name":"v999.0.0","draft":true,"prerelease":false}, - {"tag_name":"v0.0.1-nightly.20260229.1","draft":false,"prerelease":true}, - {"tag_name":"v01.2.3","draft":false,"prerelease":false}, - {"tag_name":"v18446744073709551616.0.0","draft":false,"prerelease":false}, - {"tag_name":"v0.0.1-nightly.20261017.18446744073709551616","draft":false,"prerelease":true} + {"ref":"refs/tags/v0.0.1-nightly.20261017.2","url":"quoted \"ref\": \"refs/tags/v999.9.9\""}, + {"ref":"refs/tags/cli-v999.0.0"}, + {"ref":"refs/tags/www-v999.0.0-nightly.20261017.99"}, + {"ref":"refs/tags/mobile-v999.0.0-nightly.20261017.99"}, + {"ref":"refs/tags/v1.9.0"}, + {"ref":"refs/tags/v0.0.1-nightly.20261017.10","object":{"sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","type":"tag"}}, + {"ref":"refs/tags/v1.10.0"}, + {"ref":"refs/tags/v999.0.0-rc.1"}, + {"ref":"refs/tags/v0.0.1-nightly.20260229.1"}, + {"ref":"refs/tags/v01.2.3"}, + {"ref":"refs/tags/v18446744073709551616.0.0"}, + {"ref":"refs/tags/v0.0.1-nightly.20261017.18446744073709551616"} ] JSON - json_fields "$fixture/releases.json" releases > "$fixture/fields" + json_fields "$fixture/refs.json" refs > "$fixture/fields" || fail 'self-test: tag refs did not parse' [[ $(select_release "$fixture/fields" stable) == v1.10.0 ]] || fail 'self-test: Stable numeric sorting or channel isolation' [[ $(select_release "$fixture/fields" nightly) == v0.0.1-nightly.20261017.10 ]] || fail 'self-test: Nightly numeric sorting or channel isolation' + local bad_ref + for bad_ref in refs/heads/v1.0.0 refs/abcdev1.0.0 'refs/tags/v1.0.0$(id)' refs/tags/../v1.0.0 refs/tags/v1.0.0/x; do + printf '[{"ref":"%s"}]\n' "$bad_ref" > "$fixture/bad-refs.json" + if json_fields "$fixture/bad-refs.json" refs > /dev/null; then fail "self-test: accepted tag ref $bad_ref"; fi + done + printf '[{"ref":"refs/tags/v0.0.1-nightly.20261017.2"}]\n' > "$fixture/compact.json" + json_fields "$fixture/compact.json" refs > "$fixture/compact-fields" + awk 'BEGIN { print "["; print "{"; print "\"ref\":"; print "\"refs/tags/v0.0.1-nightly.20261017.2\","; printf "\"url\":\""; for (i=0;i<10000;i++) printf "ignored "; print "\""; print "}"; print "]" }' > "$fixture/pretty.json" + json_fields "$fixture/pretty.json" refs > "$fixture/pretty-fields" + cmp "$fixture/compact-fields" "$fixture/pretty-fields" || fail 'self-test: pretty JSON changed tag fields' + write_releases v0.0.1-nightly.20261017.2:false:true v0.0.1-nightly.20261017.10:false:true v1.9.0:false:false v999.0.0:true:false version=0.0.1-nightly.20261017.10 target=x86_64-unknown-linux-gnu package="vibeface-$version-$target" @@ -716,18 +758,9 @@ JSON [[ $(cat "$case_dir/bin/vibeface") == 'preserve me' ]] || fail 'self-test: bin conflict changed' case_dir="$test_dir/no-stable" mkdir "$case_dir" - printf '[{"tag_name":"v%s","draft":false,"prerelease":true}]\n' "$version" > "$fixture/releases.json" + write_releases "v$version:false:true" expect_failure stable 'no published Stable release' [[ ! -e "$case_dir/root" ]] || fail 'self-test: no Stable release created installation directories' - # Page-local indexes must not overwrite earlier candidates. - json_fields "$fixture/releases.json" releases 1 > "$fixture/fields" - printf '[{"tag_name":"v0.0.1-nightly.20261017.2","draft":false,"prerelease":true}]\n' > "$fixture/page2.json" - json_fields "$fixture/page2.json" releases 2 >> "$fixture/fields" - [[ $(select_release "$fixture/fields" nightly) == "v$version" ]] || fail 'self-test: pagination changed version selection' - json_fields "$fixture/page2.json" releases 2 > "$fixture/compact-fields" - awk 'BEGIN { print "["; print "{"; print "\"tag_name\":\"v0.0.1-nightly.20261017.2\","; print "\"draft\":false,"; print "\"prerelease\":true,"; printf "\"body\":\""; for (i=0;i<10000;i++) printf "ignored "; print "\""; print "}"; print "]" }' > "$fixture/pretty.json" - json_fields "$fixture/pretty.json" releases 2 > "$fixture/pretty-fields" - cmp "$fixture/compact-fields" "$fixture/pretty-fields" || fail 'self-test: pretty JSON changed release fields' case_dir="$test_dir/http-failure" mkdir "$case_dir" : > "$fixture/http-failure" @@ -739,13 +772,7 @@ JSON printf '%s' "$2" > "$fixture/marker-code/$1" } progressive_releases() { - cat > "$fixture/releases.json" <<'JSON' -[ - {"tag_name":"v0.0.1-nightly.20261017.99","draft":false,"prerelease":true}, - {"tag_name":"v0.0.1-nightly.20261017.10","draft":false,"prerelease":true}, - {"tag_name":"v1.9.0","draft":false,"prerelease":false} -] -JSON + write_releases v0.0.1-nightly.20261017.99:false:true v0.0.1-nightly.20261017.10:false:true v1.9.0:false:false } cp "$fixture/supported-build" "$fixture/source/$package/BUILD-INFO.json" repack_fixture @@ -788,7 +815,7 @@ JSON mkdir "$case_dir" expect_failure nightly 'release completion manifest identity or target binding is invalid' reset_progressive_markers - printf '[{"tag_name":"v%s","draft":false,"prerelease":true}]\n' "$version" > "$fixture/releases.json" + write_releases "v$version:false:true" marker_code "v$version" 503 case_dir="$test_dir/marker-transport" mkdir "$case_dir" @@ -813,8 +840,35 @@ JSON mkdir "$case_dir" expect_failure nightly 'no published Nightly release' reset_progressive_markers + # A newer tag whose release is a draft, carries the wrong prerelease flag or does not exist yet + # is skipped; if it were chosen, its completion manifest would not match it and the run fails. + local skipped + for skipped in v0.0.1-nightly.20261017.99:true:true v0.0.1-nightly.20261017.99:false:false v0.0.1-nightly.20261017.99; do + write_releases "$skipped" "v$version:false:true" + case_dir="$test_dir/skip-${skipped//:/-}" + mkdir "$case_dir" + bash "$script" --channel nightly --install-root "$case_dir/root" --bin-dir "$case_dir/bin" > "$case_dir/output" + [[ $("$case_dir/bin/vibeface" --version) == "vibeface $version" ]] || fail "self-test: $skipped was not skipped" + done + write_releases v0.0.1-nightly.20261017.99:false:true "v$version:false:true" + cp "$fixture/release/v$version.json" "$fixture/release/v0.0.1-nightly.20261017.99.json" + case_dir="$test_dir/release-tag-mismatch" + mkdir "$case_dir" + expect_failure nightly 'release lookup returned a different tag' + # Sixteen releases are looked up at most; the complete one after them is not reached. + local n missing=() + for ((n=1; n<=16; n++)); do missing+=("v0.0.1-nightly.20261018.$n"); done + write_releases "${missing[@]:1}" "v$version:false:true" + case_dir="$test_dir/probe-limit-reached" + mkdir "$case_dir" + bash "$script" --channel nightly --install-root "$case_dir/root" --bin-dir "$case_dir/bin" > "$case_dir/output" + [[ $("$case_dir/bin/vibeface" --version) == "vibeface $version" ]] || fail 'self-test: sixteenth candidate was not looked up' + write_releases "${missing[@]}" "v$version:false:true" + case_dir="$test_dir/probe-limit-exceeded" + mkdir "$case_dir" + expect_failure nightly 'none of the 16 newest candidate releases is complete' service_self_test "$(dirname "$script")/scripts/install-node-service.sh" "$test_dir/service" - printf 'Public installer self-test passed: channels, numeric sorting, layout, SHA256, manifest, links, paths, progressive completion, and existing-install protection.\n' + printf 'Public installer self-test passed: tag discovery, channels, numeric sorting, layout, SHA256, manifest, links, paths, progressive completion, and existing-install protection.\n' ) if [[ ${1:-} == --self-test ]]; then diff --git a/packages/docs/releasing.md b/packages/docs/releasing.md index c6976201..69919cb4 100644 --- a/packages/docs/releasing.md +++ b/packages/docs/releasing.md @@ -156,7 +156,7 @@ gh workflow run release-www.yml --ref -F publish=false npm Nightly 的制品与发布流程见下面的 npm 章节。npm 安装由 npm 更新,不使用本节的 Rust 自更新器。 -Rust 更新器从 `leaperone/vibeface` 的公开 GitHub Releases 发现版本,不使用 Actions 的临时制品。Stable 只选择 `vX.Y.Z` 正式版,Nightly 只选择 `vX.Y.Z-nightly.YYYYMMDD.N` 预发布;两者都不选择 rc。新版更新器跳过缺少完整 `release.json` 的构建中 Release,再比较数值版本,不按 Release 创建时间或字符串排序,不自动降级。已安装旧客户端可能先消费自己平台已经齐备的完整包与校验文件;目标不齐时失败并保留现版。尚无正式版时,Stable 报告没有匹配版本,不回退到 Nightly。 +Rust 更新器从 `leaperone/vibeface` 的公开 GitHub Releases 发现版本,不使用 Actions 的临时制品。Stable 只选择 `vX.Y.Z` 正式版,Nightly 只选择 `vX.Y.Z-nightly.YYYYMMDD.N` 预发布;两者都不选择 rc。新版更新器跳过缺少完整 `release.json` 的构建中 Release,再比较数值版本,不按 Release 创建时间或字符串排序,不自动降级。完整 Release 列表随每个版本的数十个附件增长,更新器不下载它:先用一次请求读取全部 `v` tag 引用,按数值版本排出本渠道中比当前版本新的 tag,再从新到旧逐个查询这些 Release,草稿或尚未创建 Release 的 tag 返回 404 并跳过。最多查询 16 个候选,都不完整时报错,不当作没有更新。已安装旧客户端可能先消费自己平台已经齐备的完整包与校验文件;目标不齐时失败并保留现版。尚无正式版时,Stable 报告没有匹配版本,不回退到 Nightly。 更新确认提交后,安装目录保留当前包与最近一次 journal 的 previous。清理只处理同一 Node 曾确认提交、内容摘要未改变且不再引用的旧包,并保护正在执行的 CLI 包。未知目录、未提交候选、残留 staging、其他 Node 的记录和含链接的包均保留;失败或中断且 journal 尚在时不清理。 @@ -172,7 +172,7 @@ Rust 更新器从 `leaperone/vibeface` 的公开 GitHub Releases 发现版本, ## 首次安装 -公开安装入口为仓库根 `install.sh`。默认选择最新 Stable,显式 `--channel nightly` 选择最新 Nightly;按数值版本比较,忽略 rc、draft 和缺少完整清单的构建中版本,不使用 `/releases/latest` 获取 Nightly。如果尚无正式版,Stable 安装会明确失败。命令和后续 CLI 管理见 [安装说明](install.md)。 +公开安装入口为仓库根 `install.sh`。默认选择最新 Stable,显式 `--channel nightly` 选择最新 Nightly;按数值版本比较,忽略 rc、draft 和缺少完整清单的构建中版本,不使用 `/releases/latest` 获取 Nightly。候选来源与更新器相同:读取 tag 引用后从新到旧逐个查询 Release,最多 16 个,不下载完整 Release 列表。如果尚无正式版,Stable 安装会明确失败。命令和后续 CLI 管理见 [安装说明](install.md)。 安装器只依赖 Bash、curl、tar、gzip、系统文本工具及 `sha256sum` 或 `shasum`,不需要 jq、Python、Node.js 或 Rust。它解析公开 Releases 和 tag 对应的源码提交,下载完整包与准确同名的 SHA256,校验版本、target、源码身份、协议和 data epoch,并拒绝危险包路径、符号链接和特殊文件。校验通过后建立 `releases/`、`current` 与用户 bin 链接,不覆盖已有安装、身份或服务。 diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 3a2e645d..052b5078 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -32,16 +32,14 @@ function Fail { exit 1 } -# The release tags of one channel, newest last. A tag of another product, a draft, or a tag -# whose shape is not exactly this project's is left out rather than guessed at. +# The release tags of one channel, newest last. A tag of another product, or a tag whose shape +# is not exactly this project's, is left out rather than guessed at. Whether a tag's release is +# published, a draft or a prerelease is checked when that release is looked up. function Select-Release { - param([object[]] $Releases, [string] $Channel) + param([string[]] $Tags, [string] $Channel) $wanted = $Channel -eq 'nightly' $ordered = @() - foreach ($release in $Releases) { - if ($release.draft -ne $false) { continue } - if ($release.prerelease -ne $wanted) { continue } - $tag = [string] $release.tag_name + foreach ($tag in $Tags) { $shape = if ($wanted) { '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-nightly\.([0-9]{8})\.([1-9][0-9]*)$' } else { @@ -73,21 +71,34 @@ function Select-Release { return ($ordered | Sort-Object Major, Minor, Patch, Day, Build) } +# Returns $false only for HTTP 404; any other failure stops the installation. function Get-OptionalDownload { - param([string] $Url, [string] $Path, [int64] $Limit) + param([string] $Url, [string] $Path, [int64] $Limit, [string] $Label = 'completion manifest', + [string] $Accept = '*/*') try { Invoke-WebRequest -Uri $Url -OutFile $Path -UseBasicParsing -MaximumRedirection 5 ` - -UserAgent 'vibeface-installer' -TimeoutSec 180 + -Headers @{ Accept = $Accept } -UserAgent 'vibeface-installer' -TimeoutSec 180 } catch { $status = 0 if ($_.Exception.Response) { $status = [int]$_.Exception.Response.StatusCode } if ($status -eq 404) { return $false } - Fail 'completion manifest download failed (network or GitHub API limit)' + Fail "$Label download failed (network or GitHub API limit)" } - if ((Get-Item -LiteralPath $Path).Length -gt $Limit) { Fail 'release completion manifest exceeds limit' } + if ((Get-Item -LiteralPath $Path).Length -gt $Limit) { Fail "$Label exceeds its size limit" } return $true } +function Get-OptionalJson { + param([string] $Url, [string] $Label) + $file = Join-Path $script:Scratch ('json-' + [guid]::NewGuid().ToString('N')) + if (-not (Get-OptionalDownload -Url $Url -Path $file -Limit $MaxJson -Label $Label ` + -Accept 'application/vnd.github+json')) { + return $null + } + try { return (Get-Content -LiteralPath $file -Raw | ConvertFrom-Json -ErrorAction Stop) } + catch { Fail 'invalid GitHub release response' } +} + function Confirm-Completion { param([object] $Release, [string] $Tag, [string] $Version, [string] $Archive, [string] $Target) $marker = @($Release.assets | Where-Object { $_.name -eq 'release.json' }) @@ -283,15 +294,14 @@ function Install-Release { Fail 'vibeface already exists in the bin directory; use update apply for a managed installation' } - $releases = @() - $complete = $false - for ($page = 1; $page -le 20; $page++) { - $batch = @(Get-Json -Url "$Api/releases?per_page=100&page=$page") - $releases += $batch - if ($batch.Count -lt 100) { $complete = $true; break } - } - if (-not $complete) { Fail 'release list exceeds 20 pages; cannot select the latest version safely' } - $selected = @(Select-Release -Releases $releases -Channel $Channel) + # The full release listing grows by every release's assets; tag refs stay small. Order the + # channel's tags by version, then look up only those releases, newest first. + $tags = @(@(Get-Json -Url "$Api/git/matching-refs/tags/v") | ForEach-Object { + $name = [string] $_.ref + if (-not $name.StartsWith('refs/tags/', [StringComparison]::Ordinal)) { Fail 'invalid GitHub tag response' } + $name.Substring(10) + }) + $selected = @(Select-Release -Tags $tags -Channel $Channel) if ($selected.Count -eq 0) { if ($Channel -eq 'stable') { Fail 'no published Stable release; pass -Channel nightly explicitly to install a preview' @@ -299,11 +309,21 @@ function Install-Release { Fail 'no published Nightly release' } $chosen = $null + $probed = 0 for ($index = $selected.Count - 1; $index -ge 0; $index--) { + if ($probed -eq 16) { + Fail 'none of the 16 newest candidate releases is complete; cannot select the latest version safely' + } + $probed++ $candidateTag = $selected[$index].Tag + # Drafts and tags whose release has not been created yet answer 404. + $release = Get-OptionalJson -Url "$Api/releases/tags/$candidateTag" -Label 'release lookup' + if ($null -eq $release) { continue } + if ([string] $release.tag_name -cne $candidateTag) { Fail 'release lookup returned a different tag' } + if ($release.draft -ne $false -or $release.prerelease -ne ($Channel -eq 'nightly')) { continue } $candidateVersion = $candidateTag.Substring(1) $candidatePackage = "vibeface-$candidateVersion-$Target" - $candidateManifest = Confirm-Completion -Release ($releases | Where-Object tag_name -CEQ $candidateTag | Select-Object -First 1) ` + $candidateManifest = Confirm-Completion -Release $release ` -Tag $candidateTag -Version $candidateVersion -Archive "$candidatePackage.tar.gz" -Target $Target if ($candidateManifest) { $tag = $candidateTag; $version = $candidateVersion; $package = $candidatePackage @@ -396,21 +416,11 @@ function Install-Release { # Checks the parts that need no network: tag selection, archive refusal, and the shim. function Invoke-SelfTest { - $stable = @( - [pscustomobject]@{ tag_name = 'v1.9.0'; draft = $false; prerelease = $false }, - [pscustomobject]@{ tag_name = 'v1.10.0'; draft = $false; prerelease = $false }, - [pscustomobject]@{ tag_name = 'v999.0.0'; draft = $true; prerelease = $false }, - [pscustomobject]@{ tag_name = 'cli-v999.0.0'; draft = $false; prerelease = $false }, - [pscustomobject]@{ tag_name = 'v01.2.3'; draft = $false; prerelease = $false }, - [pscustomobject]@{ tag_name = 'v999.0.0-rc.1'; draft = $false; prerelease = $true }, - [pscustomobject]@{ tag_name = 'v0.0.1-nightly.20261017.2'; draft = $false; prerelease = $true }, - [pscustomobject]@{ tag_name = 'v0.0.1-nightly.20261017.10'; draft = $false; prerelease = $true }, - [pscustomobject]@{ tag_name = 'v0.0.1-nightly.20260229.1'; draft = $false; prerelease = $true }, - [pscustomobject]@{ tag_name = 'www-v999.0.0-nightly.20261017.99'; draft = $false; prerelease = $true } - ) - $picked = @(Select-Release -Releases $stable -Channel 'stable') + $candidates = @('v1.9.0', 'v1.10.0', 'cli-v999.0.0', 'v01.2.3', 'v999.0.0-rc.1', 'v0.0.1-nightly.20261017.2', + 'v0.0.1-nightly.20261017.10', 'v0.0.1-nightly.20260229.1', 'www-v999.0.0-nightly.20261017.99') + $picked = @(Select-Release -Tags $candidates -Channel 'stable') if ($picked[-1].Tag -ne 'v1.10.0') { Fail "self-test: stable selection picked $($picked[-1].Tag)" } - $picked = @(Select-Release -Releases $stable -Channel 'nightly') + $picked = @(Select-Release -Tags $candidates -Channel 'nightly') if ($picked[-1].Tag -ne 'v0.0.1-nightly.20261017.10') { Fail "self-test: nightly selection picked $($picked[-1].Tag)" } @@ -488,9 +498,20 @@ public class VibefaceInstallerTestResponse : System.Net.WebResponse { -Archive "vibeface-0.0.1-nightly.20261108.99-$Target.tar.gz" -Target $Target) { throw 'self-test: HTTP 404 marker was treated as complete' } - $responses["$Api/releases?per_page=100&page=1"] = @{ - Code = 200; Body = (@($building, $complete) | ConvertTo-Json -Depth 10 -Compress) + # Tag refs list every release; a tag listed under Missing has no release yet. + function Set-Releases { + param([object[]] $Published, [string[]] $Missing = @()) + $names = @(@($Published | ForEach-Object { [string] $_.tag_name }) + $Missing) + $refs = @($names | ForEach-Object { [pscustomobject]@{ ref = "refs/tags/$_" } }) + $responses["$Api/git/matching-refs/tags/v"] = @{ Code = 200; Body = (ConvertTo-Json -InputObject $refs -Compress) } + foreach ($release in $Published) { + $responses["$Api/releases/tags/$($release.tag_name)"] = @{ + Code = 200; Body = ($release | ConvertTo-Json -Depth 10 -Compress) + } + } + foreach ($name in $Missing) { $responses["$Api/releases/tags/$name"] = @{ Code = 404; Body = '' } } } + Set-Releases -Published @($building, $complete) $responses["$Api/commits/$tag"] = @{ Code = 200; Body = '{"sha":"7845e46d9c5b04b66eb7a66bcda31572e1ef7f4a"}' } $install = Join-Path $script:Scratch 'install' $bin = Join-Path $script:Scratch 'bin' @@ -500,6 +521,34 @@ public class VibefaceInstallerTestResponse : System.Net.WebResponse { if ($requests[$requests.Count - 1] -cne "$Downloads/$tag/$archive") { throw 'self-test: newest Building did not select the older complete archive' } + # A newer tag whose release is missing, a draft or not a prerelease is passed over without + # reading its completion manifest. + $draft = $building.PSObject.Copy(); $draft.draft = $true + $final = $building.PSObject.Copy(); $final.prerelease = $false + foreach ($case in @(@{ Published = @($complete); Missing = @($building.tag_name) }, + @{ Published = @($draft, $complete); Missing = @() }, + @{ Published = @($final, $complete); Missing = @() })) { + Set-Releases -Published $case.Published -Missing $case.Missing + $requests.Clear() + Assert-InstallerError { Install-Release -Channel nightly -InstallRoot $install -BinDir $bin } 'download failed' + if ($requests.Contains($buildingUrl) -or $requests[$requests.Count - 1] -cne "$Downloads/$tag/$archive") { + throw 'self-test: an unpublished newer release was not skipped' + } + } + Set-Releases -Published @($building, $complete) + $responses["$Api/releases/tags/$($building.tag_name)"] = $responses["$Api/releases/tags/$tag"] + Assert-InstallerError { Install-Release -Channel nightly -InstallRoot $install -BinDir $bin } 'release lookup returned a different tag' + # Sixteen releases are looked up at most; the complete one after them is not reached. + $missing = @(1..16 | ForEach-Object { "v0.0.1-nightly.20261109.$_" }) + Set-Releases -Published @($complete) -Missing ($missing | Select-Object -Skip 1) + $requests.Clear() + Assert-InstallerError { Install-Release -Channel nightly -InstallRoot $install -BinDir $bin } 'download failed' + if ($requests[$requests.Count - 1] -cne "$Downloads/$tag/$archive") { + throw 'self-test: the sixteenth candidate release was not looked up' + } + Set-Releases -Published @($complete) -Missing $missing + Assert-InstallerError { Install-Release -Channel nightly -InstallRoot $install -BinDir $bin } 'none of the 16 newest candidate releases is complete' + Set-Releases -Published @($building, $complete) foreach ($code in @(403, 503)) { $responses[$buildingUrl] = @{ Code = $code; Body = '' } $requests.Clear() From 9be13255e05cf92275bded24fc62d8e20ffcd0df Mon Sep 17 00:00:00 2001 From: cunoe Date: Thu, 12 Nov 2026 22:57:55 -0800 Subject: [PATCH 3/5] test(install): keep the unsafe tag-ref case free of shell expansions shellcheck reports SC2016 for the literal $(id) test input. A semicolon is rejected by the same character check without looking like an expansion. --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 0f8004dd..2e1c9d52 100755 --- a/install.sh +++ b/install.sh @@ -601,7 +601,7 @@ JSON [[ $(select_release "$fixture/fields" stable) == v1.10.0 ]] || fail 'self-test: Stable numeric sorting or channel isolation' [[ $(select_release "$fixture/fields" nightly) == v0.0.1-nightly.20261017.10 ]] || fail 'self-test: Nightly numeric sorting or channel isolation' local bad_ref - for bad_ref in refs/heads/v1.0.0 refs/abcdev1.0.0 'refs/tags/v1.0.0$(id)' refs/tags/../v1.0.0 refs/tags/v1.0.0/x; do + for bad_ref in refs/heads/v1.0.0 refs/abcdev1.0.0 'refs/tags/v1.0.0;id' refs/tags/../v1.0.0 refs/tags/v1.0.0/x; do printf '[{"ref":"%s"}]\n' "$bad_ref" > "$fixture/bad-refs.json" if json_fields "$fixture/bad-refs.json" refs > /dev/null; then fail "self-test: accepted tag ref $bad_ref"; fi done From fbc67da82472e809df911dd2c49c1f22e67905df Mon Sep 17 00:00:00 2001 From: cunoe Date: Thu, 12 Nov 2026 22:57:55 -0800 Subject: [PATCH 4/5] test(cli): pass platform absolute recovery paths in the recovery review test The test added in #556 passes /tmp/original.json to --recovery-file, which must be absolute. That path is not absolute on Windows, so the first parse fails there and the Windows CLI scope has been red on main; the two expected-error assertions also passed on Windows for the wrong reason. Build both paths from the temp directory, as the neighbouring test does. --- apps/cli/src/manage.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/cli/src/manage.rs b/apps/cli/src/manage.rs index bcbd85ef..88637f1f 100644 --- a/apps/cli/src/manage.rs +++ b/apps/cli/src/manage.rs @@ -1176,12 +1176,21 @@ mod tests { #[test] fn recovery_review_needs_no_replacement_file_and_keeps_selection_explicit() -> Result<()> { + // Recovery files must be absolute; `/tmp/...` is not absolute on Windows. + let original = std::env::temp_dir() + .join("original.json") + .display() + .to_string(); + let replacement = std::env::temp_dir() + .join("replacement.json") + .display() + .to_string(); let Command::Client(options) = parse(&[ "client", "recover", "--review", "--recovery-file", - "/tmp/original.json", + &original, ])? else { anyhow::bail!("expected client recovery") @@ -1198,14 +1207,14 @@ mod tests { assert!(review); assert_eq!(new_recovery_file, None); assert_eq!(members, None); - assert!(parse(&["client", "recover", "--recovery-file", "/tmp/original.json"]).is_err()); + assert!(parse(&["client", "recover", "--recovery-file", &original]).is_err()); assert!( parse(&[ "client", "recover", "--review", "--recovery-file", - "/tmp/original.json", + &original, "--members", "[]" ]) @@ -1215,9 +1224,9 @@ mod tests { "client", "recover", "--recovery-file", - "/tmp/original.json", + &original, "--new-recovery-file", - "/tmp/replacement.json", + &replacement, "--members", "[]", ])? From 6c15e67e51eba3b1f7ad619080d9f79ee64098c6 Mon Sep 17 00:00:00 2001 From: cunoe Date: Thu, 12 Nov 2026 23:31:20 -0800 Subject: [PATCH 5/5] fix(release): keep package size bounds ahead of growth Two sets of size bounds are about to be outgrown by the packages they check. The npm package bundles all four platform packages and is verified in collect with a 512 MiB decompression bound and a 384 MiB compressed bound. 0.0.1-nightly.20261112.3 is already 491.6 MB unpacked and 175 MB packed, after 216 MB on 2026-11-06. Once collect fails on the bound, publish-product never writes release.json, so no installer or updater sees the release and the Nightly coordinator stops. Raise the bounds to 2 GiB unpacked and 1 GiB packed, shared by both checks. The updater and both installers refuse platform archives over 128 MiB and packages over 512 MiB unpacked. The largest archive is 42.9 MiB today and grew 1.3-2.7 MiB a day, so it would pass the bound in one to two months. That limit locks itself: an installed updater can never download the release that raises it. Raise it to 1 GiB packed and 2 GiB unpacked now, while nodes can still take the update. --- apps/cli/src/update/release.rs | 7 +++++-- install.sh | 7 ++++--- scripts/install.ps1 | 5 +++-- scripts/package-npm.mjs | 13 ++++++++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/cli/src/update/release.rs b/apps/cli/src/update/release.rs index 940573fe..21cff3d9 100644 --- a/apps/cli/src/update/release.rs +++ b/apps/cli/src/update/release.rs @@ -21,8 +21,11 @@ const API: &str = "https://api.github.com/repos/leaperone/vibeface"; /// Releases fetched one by one, newest first, before discovery gives up on finding a complete one. const MAX_CANDIDATES: usize = 16; const MAX_JSON: u64 = 4 * 1024 * 1024; -const MAX_ARCHIVE: u64 = 128 * 1024 * 1024; -const MAX_UNPACKED: u64 = 512 * 1024 * 1024; +// Bounds against a corrupt or hostile download, kept far above real packages (about 45 MiB packed +// and 130 MiB unpacked in November 2026). An updater can never install a release past its own +// bounds, so they must stay ahead of package growth rather than track it. +const MAX_ARCHIVE: u64 = 1024 * 1024 * 1024; +const MAX_UNPACKED: u64 = 2 * 1024 * 1024 * 1024; const MAX_ENTRIES: usize = 4096; /// The programs a package carries, named the way this platform names a program. diff --git a/install.sh b/install.sh index 2e1c9d52..c40363bd 100755 --- a/install.sh +++ b/install.sh @@ -187,8 +187,9 @@ sha256() { check_archive() { local archive="$1" package="$2" scratch="$3" length # Bound decompression before tar reads any member, then reject links and special files. - length=$(gzip -dc "$archive" | head -c 536870913 | wc -c) || fail 'invalid or oversized compressed archive' - ((length <= 536870912)) || fail 'expanded archive exceeds size limit' + # The bounds stay far above real packages: a release past them could never be installed here. + length=$(gzip -dc "$archive" | head -c 2147483649 | wc -c) || fail 'invalid or oversized compressed archive' + ((length <= 2147483648)) || fail 'expanded archive exceeds size limit' tar -tzf "$archive" > "$scratch/entries" || fail 'invalid tar archive' awk -v root="$package" ' { @@ -322,7 +323,7 @@ install_release() ( [[ $commit =~ ^[0-9a-f]{40}$ ]] || fail 'release tag has no valid source commit' [[ $(awk -F '\t' '{print $1}' <<< "$manifest_fields") == "$commit" ]] || fail 'completion manifest source does not match release tag' printf 'Downloading %s (%s)...\n' "$tag" "$target" - fetch "https://github.com/leaperone/vibeface/releases/download/$tag/$archive" "$scratch/$archive" 134217728 + fetch "https://github.com/leaperone/vibeface/releases/download/$tag/$archive" "$scratch/$archive" 1073741824 fetch "https://github.com/leaperone/vibeface/releases/download/$tag/$archive.sha256" "$scratch/checksum" 4096 [[ $(wc -c < "$scratch/$archive" | tr -d ' ') == $(awk -F '\t' '{print $4}' <<< "$manifest_fields") && $(wc -c < "$scratch/checksum" | tr -d ' ') == $(awk -F '\t' '{print $5}' <<< "$manifest_fields") ]] || fail 'release completion manifest target sizes mismatch' diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 052b5078..629d8704 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -22,8 +22,9 @@ $Target = 'x86_64-pc-windows-msvc' $Api = 'https://api.github.com/repos/leaperone/vibeface' $Downloads = 'https://github.com/leaperone/vibeface/releases/download' $MaxJson = 4MB -$MaxArchive = 128MB -$MaxUnpacked = 512MB +# Far above real packages: a release past these bounds could never be installed here. +$MaxArchive = 1GB +$MaxUnpacked = 2GB $MaxEntries = 4096 function Fail { diff --git a/scripts/package-npm.mjs b/scripts/package-npm.mjs index 0b014687..be67930e 100644 --- a/scripts/package-npm.mjs +++ b/scripts/package-npm.mjs @@ -28,8 +28,15 @@ const updateProtocol = Number(/pub const UPDATE_PROTOCOL: u32 = (\d+);/.exec(con const dataEpoch = Number(/pub const DATA_EPOCH: u32 = (\d+);/.exec(control)?.[1]); assert(Number.isSafeInteger(updateProtocol) && Number.isSafeInteger(dataEpoch), 'missing release protocol constants'); +// The npm package carries all four platform bundles, so it grows four times as fast as one of +// them. These bounds only stop a corrupt archive; collect fails on them and blocks the whole +// product release, so they stay far above the real package (175 MB packed and 492 MB unpacked in +// November 2026). +const MAX_PACKED = 1024 * 1024 * 1024; +const MAX_UNPACKED = 2 * 1024 * 1024 * 1024; + function verifyTarMetadata(compressed) { - const bytes = gunzipSync(compressed, { maxOutputLength: 512 * 1024 * 1024 }); + const bytes = gunzipSync(compressed, { maxOutputLength: MAX_UNPACKED }); const text = (header, start, length) => header.subarray(start, start + length).toString('utf8').replace(/\0.*$/s, '').trim(); for (let offset = 0; offset + 512 <= bytes.length;) { const header = bytes.subarray(offset, offset + 512); @@ -61,8 +68,8 @@ function nightly(version) { } function unpack(archive, destination, root) { - assert(fs.statSync(archive).size <= 384 * 1024 * 1024, 'compressed package is too large'); - gunzipSync(fs.readFileSync(archive), { maxOutputLength: 512 * 1024 * 1024 }); + assert(fs.statSync(archive).size <= MAX_PACKED, 'compressed package is too large'); + gunzipSync(fs.readFileSync(archive), { maxOutputLength: MAX_UNPACKED }); const entries = run('tar', ['-tzf', archive]).trimEnd().split('\n').map(entry => entry.replace(/\/$/, '')); assert(entries.length > 0 && entries.length <= 4096, 'invalid archive entry count'); assert.equal(new Set(entries).size, entries.length, 'duplicate archive paths');