From 55dc4a6d9e57a470e20da45f3d21a2cd7fbf5e3d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 20:38:37 -0800 Subject: [PATCH 01/24] Plug-in Library: a file URL cannot name a network path A local catalog's file:// URLs were decoded into a path without checking how the path starts. A URL such as file:////server/share/x.wasm, or one whose path holds a backslash or a percent-encoded / or \, could become a network path on Windows, so reading the catalog or a release named in it contacted that host. file_url_path now refuses a decoded path that starts with two separators or holds a backslash, and a percent-encoded / or \, with an error that names the reason. Local paths and drive-letter paths are read as before. The library.refresh params text, docs/plugins.md and docs/publishing-plugins.md say so. --- crates/engine/src/system/library.rs | 80 ++++++++++++++++++++++++----- docs/plugins.md | 3 +- docs/publishing-plugins.md | 4 +- 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 750ed600a..23063957f 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -324,27 +324,44 @@ enum Source { File(PathBuf), } -/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). -fn file_url_path(url: &str) -> Option { - let rest = url.strip_prefix("file://")?; +/// `file:///C:/x` or `file:///home/x` as a path (percent-decoded; no remote hosts). A path that +/// starts with two separators or holds a `\` (raw or percent-encoded), or a percent-encoded `/`, +/// is refused: on Windows such a path can name a network share, and reading it contacts that host. +fn file_url_path(url: &str) -> std::result::Result { + let bad = |why: &str| format!("bad file URL `{url}`: {why}"); + let rest = url.strip_prefix("file://").ok_or_else(|| bad("it doesn't start with file://"))?; let rest = rest.strip_prefix("localhost").unwrap_or(rest); if !rest.starts_with('/') { - return None; + return Err(bad("only local files can be read (file:///path)")); } let b = rest.as_bytes(); // `/C:/…` on Windows. - let rest = if b.len() > 2 && b.get(2) == Some(&b':') { rest.get(1..)? } else { rest }; + let rest = + if b.get(1).is_some_and(u8::is_ascii_alphabetic) && b.get(2) == Some(&b':') { rest.get(1..).ok_or_else(|| bad("bad drive letter"))? } else { rest }; let mut out = Vec::with_capacity(rest.len()); let mut bytes = rest.bytes(); while let Some(c) = bytes.next() { if c == b'%' { - let hex = [bytes.next()?, bytes.next()?]; - out.push(u8::from_str_radix(std::str::from_utf8(&hex).ok()?, 16).ok()?); + let hex = [bytes.next(), bytes.next()]; + let [Some(hi), Some(lo)] = hex else { return Err(bad("a % isn't followed by two hex digits")) }; + let byte = + std::str::from_utf8(&[hi, lo]).ok().and_then(|h| u8::from_str_radix(h, 16).ok()).ok_or_else(|| bad("a % isn't followed by two hex digits"))?; + if matches!(byte, b'/' | b'\\') { + return Err(bad("a percent-encoded / or \\ isn't allowed")); + } + out.push(byte); } else { out.push(c); } } - String::from_utf8(out).ok().map(PathBuf::from) + let path = String::from_utf8(out).map_err(|_| bad("the path isn't UTF-8"))?; + if path.contains('\\') { + return Err(bad("use / between folders, not \\")); + } + if path.starts_with("//") { + return Err(bad("network paths can't be read, only local files")); + } + Ok(PathBuf::from(path)) } /// Check `url` against the rules: `https://` on GitHub's hosts; `file://` when the catalog @@ -359,7 +376,7 @@ fn source(url: &str, catalog: Option<&str>) -> std::result::Result Vec { "Refresh Plug-in Catalog", [], None, - "{catalog?: https:// or file:// URL of an index.json (default: the community catalog), wait?}", + "{catalog?: https:// or file:// URL of an index.json (default: the community catalog; file:// takes a local path, not a network path such as //server/share), wait?}", always, refresh ), @@ -1177,10 +1194,47 @@ mod tests { assert_eq!(source("file:///C:/p/x.wasm", None), Ok(Source::File(PathBuf::from("C:/p/x.wasm")))); assert!(source("file://", None).is_err()); // Percent-decoded; no remote hosts. - assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Some(PathBuf::from("C:/My Plug-ins/José#.wasm"))); - assert_eq!(file_url_path("file://localhost/home/x.wasm"), Some(PathBuf::from("/home/x.wasm"))); + assert_eq!(file_url_path("file:///C:/My%20Plug-ins/Jos%C3%A9%23.wasm"), Ok(PathBuf::from("C:/My Plug-ins/José#.wasm"))); + assert_eq!(file_url_path("file://localhost/home/x.wasm"), Ok(PathBuf::from("/home/x.wasm"))); for no in ["file://server/share/x.wasm", "file:///bad%2", "file:///bad%zz"] { - assert_eq!(file_url_path(no), None, "{no}"); + assert!(file_url_path(no).is_err(), "{no}"); + } + } + + #[test] + fn file_urls_cannot_name_a_network_path() { + for ok in [ + ("file:///C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///c:/p/x.wasm", "c:/p/x.wasm"), + ("file:///home/me/x.wasm", "/home/me/x.wasm"), + ("file://localhost/C:/p/x.wasm", "C:/p/x.wasm"), + ("file:///home/me/a%20b/x.wasm", "/home/me/a b/x.wasm"), + ("file:///C:/p//x.wasm", "C:/p//x.wasm"), + ] { + assert_eq!(file_url_path(ok.0), Ok(PathBuf::from(ok.1)), "{}", ok.0); + } + for no in [ + // Two separators at the start: `//server/share/…`. + "file:////server/share/x.wasm", + "file://localhost//server/share/x.wasm", + "file://///server/share/x.wasm", + "file:////:x.wasm", + // Backslashes, raw or percent-encoded. + "file:///\\\\server\\share\\x.wasm", + "file:///\\server/share/x.wasm", + "file:///C:\\p\\x.wasm", + "file:///%5C%5Cserver/share/x.wasm", + "file:///%5c%5cserver/share/x.wasm", + "file:///C:/p%5Cx.wasm", + // Percent-encoded slashes. + "file:///%2F%2Fserver/share/x.wasm", + "file:///%2fserver/share/x.wasm", + "file:///C:/p%2Fx.wasm", + ] { + let e = file_url_path(no).expect_err(no); + assert!(e.starts_with("bad file URL"), "{no}: {e}"); + assert!(source(no, None).is_err(), "{no}"); + assert!(source(no, Some("file:///tmp/index.json")).is_err(), "{no}"); } } diff --git a/docs/plugins.md b/docs/plugins.md index 3fd8cf944..d7df3d8b1 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -369,7 +369,8 @@ package can't read files, open the network or crash the app. [`storytold/effectcraft-plugins`](https://github.com/storytold/effectcraft-plugins) repository; packages are added by pull request and reviewed there. The app has no field for another catalog; `library.refresh {catalog}` (for plug-in authors testing an entry) takes an `index.json` - on GitHub or a local file, and the page then says it shows a test catalog until Refresh. + on GitHub or a local file, and the page then says it shows a test catalog until Refresh. A file + URL that names a network path (`file:////server/share/…`) is refused. * **Nothing is downloaded until you ask.** Fetch Catalog (`library.refresh`) reads the catalog; Install (`library.install`) downloads the package's `.wasm`, checks its SHA-256 (and its size, when the catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index bd76c3ab5..0083293b6 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -226,7 +226,9 @@ Make a folder with an `index.json` that holds only your package: ``` File URLs are absolute: `file:///home/me/glow-rings/index.json` on Linux and macOS, -`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. +`file:///C:/Users/me/glow-rings/index.json` on Windows. Write a space as `%20`. Separate folders +with `/`: a file URL that holds a `\` or a percent-encoded `/` or `\`, or names a network path +(`file:////server/share/…`), is refused. Use a separate settings folder, so the test doesn't touch your real installation: From 75fed052e3dcb5cd876729863bc5e292aaca022c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 21:51:04 -0800 Subject: [PATCH 02/24] Plug-in Library: a package downloads only release assets of its repository A catalog release's url was checked only for its host: any https:// URL on GitHub's hosts was downloaded, from any repository and any path, including a raw file on a branch or a path with dot segments that curl resolves to another repository. library.install, library.update and library.preview now refuse a url that isn't https://github.com///releases/download//. When the package's repo is a https://github.com// URL, the asset must be in that repository (owner and name compared without case). Dot segments, also percent-encoded, empty segments, backslashes, queries and fragments are refused. file:// releases from a local catalog are read as before, and the SHA-256 and size checks are unchanged. A catalog other than the community one is still read only when library.refresh names it (https:// on GitHub's hosts, or a local file://). docs/plugins.md, docs/publishing-plugins.md and the library.install params text describe the rules. --- crates/engine/src/system/library.rs | 98 ++++++++++++++++++++++++++++- crates/host/tests/it/library.rs | 32 ++++++++++ docs/plugins.md | 6 +- docs/publishing-plugins.md | 2 +- 4 files changed, 134 insertions(+), 4 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 750ed600a..0e55c8acb 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -255,6 +255,58 @@ fn release_problem(r: &Release) -> Option { None } +/// An owner or repository name on GitHub: letters, digits, `.`, `-`, `_`, and not `.` or `..`. +fn valid_repo_part(p: &str) -> bool { + !p.is_empty() && p != "." && p != ".." && p.bytes().all(|b| b.is_ascii_alphanumeric() || b"._-".contains(&b)) +} + +/// The rest of `s` after `prefix`, ignoring ASCII case. +fn strip_prefix_ignore_case<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { + let head = s.get(..prefix.len())?; + head.eq_ignore_ascii_case(prefix).then(|| s.get(prefix.len()..)).flatten() +} + +/// `(owner, name)` in lower case of a `https://github.com//` repository URL (an +/// optional trailing `/` or `.git`); `None` for anything else. +fn github_repo(repo: &str) -> Option<(String, String)> { + let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; + let rest = rest.strip_suffix('/').unwrap_or(rest); + let rest = rest.strip_suffix(".git").unwrap_or(rest); + let mut parts = rest.split('/'); + let (owner, name) = (parts.next()?, parts.next()?); + (parts.next().is_none() && valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) +} + +/// Why an `https://` release URL can't be used, if it can't: it must be a release asset, +/// `https://github.com///releases/download//`, and when the package's +/// `repo` is a GitHub repository URL, `/` must be that repository. +fn release_url_problem(repo: &str, url: &str) -> Option { + let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); + let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; + if rest.contains(['?', '#', '\\']) { + return not_asset(); + } + let parts: Vec<&str> = rest.split('/').collect(); + // `.` and `..` (also percent-encoded) would move the download to another path. + let dot_segment = |p: &&str| { + let p = p.to_ascii_lowercase().replace("%2e", "."); + p == "." || p == ".." + }; + if parts.len() < 6 || parts.iter().any(|p| p.is_empty() || dot_segment(p)) { + return not_asset(); + } + let (Some(owner), Some(name), Some(releases), Some(download)) = (parts.first(), parts.get(1), parts.get(2), parts.get(3)) else { return not_asset() }; + if !valid_repo_part(owner) || !valid_repo_part(name) || *releases != "releases" || *download != "download" { + return not_asset(); + } + match github_repo(repo) { + Some((o, n)) if o != owner.to_ascii_lowercase() || n != name.to_ascii_lowercase() => { + Some(format!("`{url}` isn't a release asset of the package's repository {}", repo.trim())) + } + _ => None, + } +} + /// Read a catalog: packages and releases that are malformed are left out (and reported), so one /// bad entry doesn't hide the others. pub fn parse_catalog(bytes: &[u8]) -> std::result::Result<(Catalog, Vec), String> { @@ -799,7 +851,11 @@ fn pick(s: &Session, c: &str, p: &Value) -> Result<(String, Package, Release)> { ), )); } - source(&rel.url, Some(&url)).map_err(|e| bad(c, e))?; + if let Source::Https(u) = source(&rel.url, Some(&url)).map_err(|e| bad(c, e))? + && let Some(why) = release_url_problem(&pkg.repo, &u) + { + return Err(bad(c, why)); + } Ok((url, pkg, rel)) } @@ -1049,7 +1105,7 @@ pub fn specs() -> Vec { "Install Plug-in", [], None, - "{id, version?, wait?} — downloads the release, checks its SHA-256 against the catalog, loads it", + "{id, version?, wait?} — downloads the release (a GitHub release asset, in the package's repo when it names one), checks its SHA-256 against the catalog, loads it", always, install ), @@ -1132,6 +1188,44 @@ mod tests { assert!(latest_compatible(&Package::default()).is_none()); } + #[test] + fn release_urls_are_assets_of_the_declared_repository() { + let asset = "https://github.com/Me/Glow/releases/download/v1.0.0/glow.wasm"; + for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", "", "https://gitlab.com/me/glow"] { + assert_eq!(release_url_problem(repo, asset), None, "{repo}"); + } + assert_eq!(release_url_problem("", "https://github.com/a/b/releases/download/tags/v1/x.wasm"), None, "a tag with a slash"); + assert!( + release_url_problem("https://github.com/me/glow", "https://github.com/me/other/releases/download/v1/x.wasm") + .unwrap() + .contains("package's repository") + ); + assert!(release_url_problem("https://github.com/me/glow", "https://github.com/you/glow/releases/download/v1/x.wasm").is_some()); + for no in [ + "https://raw.githubusercontent.com/me/glow/main/x.wasm", + "https://objects.githubusercontent.com/x.wasm", + "https://github.com/me/glow/blob/main/x.wasm", + "https://github.com/me/glow/releases/download/v1", + "https://github.com/me/glow/releases/download//x.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm?x=1", + "https://github.com/me/glow/releases/download/v1/x.wasm#x", + "https://github.com/me/glow/releases/download/../../../you/evil/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/%2e%2e/%2E./x/y/x.wasm", + "https://github.com/me/glow/releases/download/./v1/x.wasm", + "https://github.com/me/glow/releases/download/v1\\x.wasm", + "https://github.com/m e/glow/releases/download/v1/x.wasm", + "https://github.com/../glow/releases/download/v1/x.wasm", + "https://github.com.evil.com/me/glow/releases/download/v1/x.wasm", + ] { + assert!(release_url_problem("https://github.com/me/glow", no).is_some(), "{no}"); + assert!(release_url_problem("", no).is_some(), "{no}"); + } + assert_eq!(github_repo("https://github.com/Me/Glow.git"), Some(("me".into(), "glow".into()))); + for no in ["https://github.com/me", "https://github.com/me/glow/tree/main", "http://github.com/me/glow", "me/glow"] { + assert_eq!(github_repo(no), None, "{no}"); + } + } + #[test] fn catalogs_leave_out_bad_entries() { let good = "a".repeat(64); diff --git a/crates/host/tests/it/library.rs b/crates/host/tests/it/library.rs index 4cd94ecdd..f5bd613cc 100644 --- a/crates/host/tests/it/library.rs +++ b/crates/host/tests/it/library.rs @@ -156,6 +156,38 @@ fn a_wrong_checksum_or_a_bad_module_installs_nothing() { let _ = std::fs::remove_dir_all(&dir); } +#[test] +fn downloads_are_release_assets_of_the_package_repository() { + let dir = tmp("assets"); + let sum = "0".repeat(64); + let pkg = + |id: &str, repo: &str, url: &str| json!({"id": id, "name": id, "repo": repo, "versions": [{"version": "1", "api": 1, "url": url, "sha256": sum}]}); + let catalog = write_catalog( + &dir, + json!([ + pkg("org.test.other", "https://github.com/me/glow", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.raw", "https://github.com/me/glow", "https://raw.githubusercontent.com/me/glow/main/glow.wasm"), + pkg("org.test.page", "", "https://github.com/me/glow/blob/main/glow.wasm"), + pkg("org.test.dots", "https://github.com/me/glow", "https://github.com/me/glow/releases/download/%2e%2e/%2E%2E/x/y/glow.wasm"), + ]), + ); + let mut s = session(&dir); + s.execute("library.refresh", json!({"catalog": catalog, "wait": true})).unwrap(); + for (id, why) in [ + ("org.test.other", "isn't a release asset of the package's repository https://github.com/me/glow"), + ("org.test.raw", "isn't a release asset"), + ("org.test.page", "isn't a release asset"), + ("org.test.dots", "isn't a release asset"), + ] { + for c in ["library.install", "library.preview"] { + let e = s.execute(c, json!({"id": id, "wait": true})).unwrap_err().to_string(); + assert!(e.contains(why), "{c} {id}: {e}"); + } + } + assert!(!dir.join("Plug-ins").join("Library").join("installed.json").exists()); + let _ = std::fs::remove_dir_all(&dir); +} + #[test] fn installed_packages_load_at_start_and_changed_files_are_refused() { let dir = tmp("startup"); diff --git a/docs/plugins.md b/docs/plugins.md index 3fd8cf944..99b91874f 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -374,7 +374,11 @@ package can't read files, open the network or crash the app. Install (`library.install`) downloads the package's `.wasm`, checks its SHA-256 (and its size, when the catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, `https://` only and starting on GitHub's hosts (redirects stay on `https://`; the SHA-256 check - is what guarantees the file). + is what guarantees the file). A package's `url` must be a release asset + (`https://github.com///releases/download/…`), in the package's `repo` when that is + a GitHub repository URL. A catalog other than the community one is read only when + `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a + local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to the settings), listed in `Library/installed.json`. Installed packages load at start-up, each checked against the SHA-256 it was installed with. The catalog last fetched is kept as diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index bd76c3ab5..c94f9e2a8 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -193,7 +193,7 @@ Release fields (one per entry in `versions`): | `version` | yes | Dotted numbers only, at most 32 characters: `1.0.0`, `1.2`. No `v` and no suffixes such as `-beta`. | | `api` | yes | The plug-in API the module implements: `1`. | | `minApp` | no | The oldest EffectCraft version the release needs (`0.17.0`). Leave it out if any version with this API works. | -| `url` | yes | The release asset's `https://` URL on GitHub. | +| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When `repo` is a `https://github.com//` URL, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | | `sha256` | yes | The file's SHA-256, 64 hex digits. | | `size` | no, but reviewed | The file's size in bytes. When it is given, a download of another size is refused. | | `effects` | yes | The effect ids the module registers (its manifest's `id`). EffectCraft uses them to find the package that provides an effect a project needs. | From 5dfcadd09bbca14eb53ec52694995eac4199f1be Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 23:24:20 -0800 Subject: [PATCH 03/24] Plug-in Library: a package with an unreadable repo URL downloads nothing When a package names a `repo` that isn't a GitHub repository URL (`https://github.com//`, a trailing `/` or `.git` allowed, or a folder in one, `.../tree//`), Install, Update and Preview now refuse its release URLs with an error naming the package. Before, such a `repo` skipped the repository check and any GitHub release asset was downloaded. A package without a `repo` keeps any repository's release asset. The example catalog's schema now holds `repo` and release `url` to the same forms, and `scripts/validate.sh` checks that every release is an asset of the package's `repo` before it downloads anything. --- crates/engine/src/system/library.rs | 100 ++++++++++++++++---- crates/host/tests/it/library.rs | 6 ++ docs/plugins.md | 6 +- docs/publishing-plugins.md | 4 +- examples/plugin-catalog/schema.json | 8 +- examples/plugin-catalog/scripts/validate.sh | 22 ++++- 6 files changed, 117 insertions(+), 29 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index 0e55c8acb..d1eaaf0bd 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -266,20 +266,33 @@ fn strip_prefix_ignore_case<'a>(s: &'a str, prefix: &str) -> Option<&'a str> { head.eq_ignore_ascii_case(prefix).then(|| s.get(prefix.len()..)).flatten() } +/// A `.` or `..` path segment, also percent-encoded. +fn dot_segment(p: &str) -> bool { + let p = p.to_ascii_lowercase().replace("%2e", "."); + p == "." || p == ".." +} + /// `(owner, name)` in lower case of a `https://github.com//` repository URL (an -/// optional trailing `/` or `.git`); `None` for anything else. +/// optional trailing `/` or `.git`) or of a folder in one, `https://github.com///tree//`; +/// `None` for anything else. fn github_repo(repo: &str) -> Option<(String, String)> { let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; + if rest.contains(['?', '#', '\\']) { + return None; + } let rest = rest.strip_suffix('/').unwrap_or(rest); - let rest = rest.strip_suffix(".git").unwrap_or(rest); - let mut parts = rest.split('/'); - let (owner, name) = (parts.next()?, parts.next()?); - (parts.next().is_none() && valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) + let parts: Vec<&str> = rest.split('/').collect(); + let (owner, name) = match parts.as_slice() { + [owner, name] => (*owner, name.strip_suffix(".git").unwrap_or(name)), + [owner, name, "tree", folder @ ..] if !folder.is_empty() && folder.iter().all(|p| !p.is_empty() && !dot_segment(p)) => (*owner, *name), + _ => return None, + }; + (valid_repo_part(owner) && valid_repo_part(name)).then(|| (owner.to_ascii_lowercase(), name.to_ascii_lowercase())) } /// Why an `https://` release URL can't be used, if it can't: it must be a release asset, -/// `https://github.com///releases/download//`, and when the package's -/// `repo` is a GitHub repository URL, `/` must be that repository. +/// `https://github.com///releases/download//`, and when the package +/// names a `repo`, that must be a GitHub repository URL (see [`github_repo`]) of `/`. fn release_url_problem(repo: &str, url: &str) -> Option { let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; @@ -287,11 +300,9 @@ fn release_url_problem(repo: &str, url: &str) -> Option { return not_asset(); } let parts: Vec<&str> = rest.split('/').collect(); - // `.` and `..` (also percent-encoded) would move the download to another path. - let dot_segment = |p: &&str| { - let p = p.to_ascii_lowercase().replace("%2e", "."); - p == "." || p == ".." - }; + // At least six segments, not exactly six: a tag may contain `/` (`release/v1`), and its assets are + // then at `releases/download/release/v1/`. `.` and `..` (also percent-encoded) would move + // the download to another path. if parts.len() < 6 || parts.iter().any(|p| p.is_empty() || dot_segment(p)) { return not_asset(); } @@ -299,11 +310,16 @@ fn release_url_problem(repo: &str, url: &str) -> Option { if !valid_repo_part(owner) || !valid_repo_part(name) || *releases != "releases" || *download != "download" { return not_asset(); } + let repo = repo.trim(); + if repo.is_empty() { + return None; + } match github_repo(repo) { - Some((o, n)) if o != owner.to_ascii_lowercase() || n != name.to_ascii_lowercase() => { - Some(format!("`{url}` isn't a release asset of the package's repository {}", repo.trim())) - } - _ => None, + Some((o, n)) if o == owner.to_ascii_lowercase() && n == name.to_ascii_lowercase() => None, + Some(_) => Some(format!("`{url}` isn't a release asset of the package's repository {repo}")), + None => Some(format!( + "the package's `repo` {repo} isn't a GitHub repository URL (https://github.com//), so `{url}` can't be checked against it" + )), } } @@ -854,7 +870,7 @@ fn pick(s: &Session, c: &str, p: &Value) -> Result<(String, Package, Release)> { if let Source::Https(u) = source(&rel.url, Some(&url)).map_err(|e| bad(c, e))? && let Some(why) = release_url_problem(&pkg.repo, &u) { - return Err(bad(c, why)); + return Err(bad(c, format!("{}: {why}", pkg.name))); } Ok((url, pkg, rel)) } @@ -1191,7 +1207,7 @@ mod tests { #[test] fn release_urls_are_assets_of_the_declared_repository() { let asset = "https://github.com/Me/Glow/releases/download/v1.0.0/glow.wasm"; - for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", "", "https://gitlab.com/me/glow"] { + for repo in ["https://github.com/me/glow", "https://github.com/Me/Glow/", "https://GitHub.com/me/glow.git", ""] { assert_eq!(release_url_problem(repo, asset), None, "{repo}"); } assert_eq!(release_url_problem("", "https://github.com/a/b/releases/download/tags/v1/x.wasm"), None, "a tag with a slash"); @@ -1221,11 +1237,57 @@ mod tests { assert!(release_url_problem("", no).is_some(), "{no}"); } assert_eq!(github_repo("https://github.com/Me/Glow.git"), Some(("me".into(), "glow".into()))); - for no in ["https://github.com/me", "https://github.com/me/glow/tree/main", "http://github.com/me/glow", "me/glow"] { + assert_eq!(github_repo("https://github.com/Me/Glow/tree/main/plugins/glow"), Some(("me".into(), "glow".into()))); + for no in ["https://github.com/me", "https://github.com/me/glow/tree", "http://github.com/me/glow", "me/glow"] { assert_eq!(github_repo(no), None, "{no}"); } } + #[test] + fn a_repo_that_isnt_a_github_repository_url_refuses_every_release() { + let asset = "https://github.com/me/glow/releases/download/v1/glow.wasm"; + for repo in [ + "https://github.com/me/glow", + "https://github.com/me/glow/", + "https://github.com/me/glow.git", + "https://github.com/me/glow.git/", + " https://github.com/ME/glow ", + "https://github.com/me/glow/tree/main", + "https://github.com/me/glow/tree/main/plugins/glow/", + "", + " ", + ] { + assert_eq!(release_url_problem(repo, asset), None, "{repo:?}"); + } + let elsewhere = release_url_problem("https://github.com/me/glow/tree/main", "https://github.com/you/evil/releases/download/v1/glow.wasm"); + assert!(elsewhere.as_deref().is_some_and(|w| w.contains("package's repository")), "{elsewhere:?}"); + for repo in [ + "https://github.com/me/glow/tree", + "https://github.com/me/glow/tree/", + "https://github.com/me/glow/tree//x", + "https://github.com/me/glow/tree/main/../../you/evil", + "https://github.com/me/glow/tree/main/%2e%2e", + "https://github.com/me/glow/blob/main/README.md", + "https://github.com/me/glow.git/x", + "https://github.com/me/glow/releases", + "https://github.com/me/glow//", + "https://github.com/me", + "https://github.com/me/", + "http://github.com/me/glow", + "github.com/me/glow", + "me/glow", + "https://www.github.com/me/glow", + "https://gitlab.com/me/glow", + "https://github.com/me/glow?tab=readme", + "https://github.com/me/glow#readme", + "https://github.com/me/gl ow", + "https://github.com/me/..", + ] { + let why = release_url_problem(repo, asset); + assert!(why.as_deref().is_some_and(|w| w.contains("isn't a GitHub repository URL")), "{repo:?}: {why:?}"); + } + } + #[test] fn catalogs_leave_out_bad_entries() { let good = "a".repeat(64); diff --git a/crates/host/tests/it/library.rs b/crates/host/tests/it/library.rs index f5bd613cc..35cbf74a7 100644 --- a/crates/host/tests/it/library.rs +++ b/crates/host/tests/it/library.rs @@ -169,6 +169,9 @@ fn downloads_are_release_assets_of_the_package_repository() { pkg("org.test.raw", "https://github.com/me/glow", "https://raw.githubusercontent.com/me/glow/main/glow.wasm"), pkg("org.test.page", "", "https://github.com/me/glow/blob/main/glow.wasm"), pkg("org.test.dots", "https://github.com/me/glow", "https://github.com/me/glow/releases/download/%2e%2e/%2E%2E/x/y/glow.wasm"), + pkg("org.test.tree", "https://github.com/me/glow/tree/main", "https://github.com/someone/else/releases/download/v1/glow.wasm"), + pkg("org.test.http", "http://github.com/me/glow", "https://github.com/me/glow/releases/download/v1/glow.wasm"), + pkg("org.test.blob", "https://github.com/me/glow/blob/main/README.md", "https://github.com/me/glow/releases/download/v1/glow.wasm"), ]), ); let mut s = session(&dir); @@ -178,6 +181,9 @@ fn downloads_are_release_assets_of_the_package_repository() { ("org.test.raw", "isn't a release asset"), ("org.test.page", "isn't a release asset"), ("org.test.dots", "isn't a release asset"), + ("org.test.tree", "isn't a release asset of the package's repository https://github.com/me/glow/tree/main"), + ("org.test.http", "org.test.http: the package's `repo` http://github.com/me/glow isn't a GitHub repository URL"), + ("org.test.blob", "org.test.blob: the package's `repo` https://github.com/me/glow/blob/main/README.md isn't a GitHub repository URL"), ] { for c in ["library.install", "library.preview"] { let e = s.execute(c, json!({"id": id, "wait": true})).unwrap_err().to_string(); diff --git a/docs/plugins.md b/docs/plugins.md index 99b91874f..5302b0b3c 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -375,8 +375,10 @@ package can't read files, open the network or crash the app. catalog gives one) against the catalog and loads it. Downloads use the system's `curl`, `https://` only and starting on GitHub's hosts (redirects stay on `https://`; the SHA-256 check is what guarantees the file). A package's `url` must be a release asset - (`https://github.com///releases/download/…`), in the package's `repo` when that is - a GitHub repository URL. A catalog other than the community one is read only when + (`https://github.com///releases/download/…`). When the package names a `repo`, the + asset must be in that repository. A `repo` that isn't `https://github.com//` (with + an optional trailing `/` or `.git`) or a folder in one (`https://github.com///tree//…`) + makes Install and Preview refuse every release of the package. A catalog other than the community one is read only when `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to diff --git a/docs/publishing-plugins.md b/docs/publishing-plugins.md index c94f9e2a8..c28554f14 100644 --- a/docs/publishing-plugins.md +++ b/docs/publishing-plugins.md @@ -181,7 +181,7 @@ Package fields: | `author` | no | You, or your group. | | `description` | no, but reviewed | One or two plain sentences that say what the effect does. | | `license` | no, but reviewed | The licence's SPDX id (`MIT`, `Apache-2.0`, `MIT OR Apache-2.0`…). | -| `repo` | no, but reviewed | The public source repository. The details' "Open on GitHub" opens it. | +| `repo` | no, but reviewed | The public source repository, as `https://github.com//` (a trailing `/` or `.git` is allowed), or a folder in it, `https://github.com///tree//`. The details' "Open on GitHub" opens it. When `repo` is given in any other form, Install and Preview refuse every release of the package. | | `tags` | no | Lower-case words for the tag filter (`blur`, `stylize`, `light`, `distort`…). Reuse tags the catalog already has. | | `preview.video` | no | An `https://` link to a short demo video on YouTube, Vimeo or GitHub. "Watch video" opens it in the browser. A link that isn't `https://` (or is longer than 500 characters) is left out. The live preview doesn't need it. | | `versions` | yes | One entry per release, newest or oldest first. | @@ -193,7 +193,7 @@ Release fields (one per entry in `versions`): | `version` | yes | Dotted numbers only, at most 32 characters: `1.0.0`, `1.2`. No `v` and no suffixes such as `-beta`. | | `api` | yes | The plug-in API the module implements: `1`. | | `minApp` | no | The oldest EffectCraft version the release needs (`0.17.0`). Leave it out if any version with this API works. | -| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When `repo` is a `https://github.com//` URL, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | +| `url` | yes | The release asset's `https://` URL on GitHub: `https://github.com///releases/download//`. When the package has a `repo`, the asset must be in that repository. Install and Preview refuse any other `https://` URL. | | `sha256` | yes | The file's SHA-256, 64 hex digits. | | `size` | no, but reviewed | The file's size in bytes. When it is given, a download of another size is refused. | | `effects` | yes | The effect ids the module registers (its manifest's `id`). EffectCraft uses them to find the package that provides an effect a project needs. | diff --git a/examples/plugin-catalog/schema.json b/examples/plugin-catalog/schema.json index a2d30676b..5fe914d86 100644 --- a/examples/plugin-catalog/schema.json +++ b/examples/plugin-catalog/schema.json @@ -12,9 +12,9 @@ }, "$defs": { "version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"}, - "github_url": { + "release_url": { "type": "string", - "pattern": "^https://(github\\.com|raw\\.githubusercontent\\.com|objects\\.githubusercontent\\.com|release-assets\\.githubusercontent\\.com)/[^\\s]+$" + "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$" }, "package": { "type": "object", @@ -26,7 +26,7 @@ "author": {"type": "string"}, "description": {"type": "string"}, "license": {"type": "string"}, - "repo": {"type": "string", "pattern": "^https://"}, + "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"}, "tags": {"type": "array", "items": {"type": "string"}}, "preview": { "type": "object", @@ -44,7 +44,7 @@ "version": {"$ref": "#/$defs/version"}, "api": {"type": "integer", "minimum": 0, "maximum": 4294967295}, "minApp": {"$ref": "#/$defs/version"}, - "url": {"$ref": "#/$defs/github_url"}, + "url": {"$ref": "#/$defs/release_url"}, "sha256": {"type": "string", "pattern": "^[0-9a-fA-F]{64}$"}, "size": {"type": "integer", "minimum": 1, "maximum": 67108864}, "effects": {"type": "array", "minItems": 1, "items": {"type": "string", "pattern": "^(?!ec\\.)[A-Za-z0-9._-]+$"}} diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 40e37de7f..60686330a 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -42,7 +42,25 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d) [ -z "$dups" ] || fail "duplicate package ids: $dups" echo "ok" -echo "== 3. downloads" +echo "== 3. release URLs" +# When a package has a `repo`, every release must be an asset of that repository, as Install and +# Preview require (the loader step installs from file:// copies, which skip this check). +bad=$(jq -r ' + # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. + def repo_of: + (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") + // capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/[^?#]+$") + | select(.h | ascii_downcase == "https://github.com") | "\(.o)/\(.n)" | ascii_downcase) // "?"; + .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo + | select($repo != "") | ($repo | repo_of) as $want + | .versions[] | select(.url | startswith("file://") | not) + | ((.url | ascii_downcase | capture("^https://github\\.com/(?[^/]+)/(?[^/]+)/releases/download/") | "\(.o)/\(.n)") // "?") as $got + | select($want == "?" or $got != $want) + | "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)"' "$catalog") +[ -z "$bad" ] || fail "release URLs outside the package's repo:"$'\n'"$bad" +echo "ok" + +echo "== 4. downloads" # The checked files are what the loader step installs: a copy of the catalog names them by file://. local_catalog=$(jq '.' "$catalog") while IFS=$'\t' read -r p r id version url sha size; do @@ -58,7 +76,7 @@ done < <(jq -r '.packages | to_entries[] | .key as $p | .value as $pkg | $pkg.ve | [$p, .key, $pkg.id, .value.version, .value.url, .value.sha256, (.value.size // "")] | @tsv' "$catalog") echo "ok" -echo "== 4. load with EffectCraft" +echo "== 5. load with EffectCraft" if [ -z "${EFFECTCRAFT_CLI:-}" ]; then echo "skipped (set EFFECTCRAFT_CLI to an effectcraft-cli build)" exit 0 From 400187f9d91b4b2e9b6995f5afb19b4bba053390 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 5 Nov 2026 23:59:53 -0800 Subject: [PATCH 04/24] Plug-in Library: the catalog validator refuses dot and empty folder segments in repo `scripts/validate.sh` now reads a `repo` folder URL (`https://github.com///tree//`) as EffectCraft does: an empty, `.` or `..` segment (also percent-encoded), or a `?`, `#` or `\`, makes the `repo` unreadable, and every release of the package is reported. A `.` or `..` owner or name is refused too. The check now matches the app when the schema step is skipped. --- examples/plugin-catalog/scripts/validate.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 60686330a..6e57e05ce 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -46,11 +46,15 @@ echo "== 3. release URLs" # When a package has a `repo`, every release must be an asset of that repository, as Install and # Preview require (the loader step installs from file:// copies, which skip this check). bad=$(jq -r ' + # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). + def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") - // capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/[^?#]+$") - | select(.h | ascii_downcase == "https://github.com") | "\(.o)/\(.n)" | ascii_downcase) // "?"; + // (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/(?[^?#\\\\]+?)/?$") + | select(.f | split("/") | any(bad_segment) | not)) + | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) + | "\(.o)/\(.n)" | ascii_downcase) // "?"; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo | select($repo != "") | ($repo | repo_of) as $want | .versions[] | select(.url | startswith("file://") | not) From cc90ad0c3b2f36c5ade8b4d9620f6e5afba0bf32 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 00:32:31 -0800 Subject: [PATCH 05/24] Plug-in Library: the catalog validator checks every remote release URL in full scripts/validate.sh now refuses any release URL other than a local file:// path that isn't a release asset (https://github.com///releases/download// with no query, fragment, backslash, or empty, . or .. segment), for packages without a repo too, as Install and Preview do. docs/plugins.md says the release URL rules don't apply to file:// releases from a local catalog. --- docs/plugins.md | 4 ++- examples/plugin-catalog/scripts/validate.sh | 28 +++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 5302b0b3c..cc4f164aa 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -378,7 +378,9 @@ package can't read files, open the network or crash the app. (`https://github.com///releases/download/…`). When the package names a `repo`, the asset must be in that repository. A `repo` that isn't `https://github.com//` (with an optional trailing `/` or `.git`) or a folder in one (`https://github.com///tree//…`) - makes Install and Preview refuse every release of the package. A catalog other than the community one is read only when + makes Install and Preview refuse every `https://` release of the package. These rules don't apply + to a release whose `url` is a local `file://` path, which only a local catalog may name (to test + an entry before its release is published). A catalog other than the community one is read only when `library.refresh {catalog}` names it: an `index.json` on GitHub's hosts over `https://`, or a local `file://` path. * **Where it goes.** `/Library///.wasm` (the `Plug-ins` folder next to diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 6e57e05ce..4a0d196fc 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -43,11 +43,24 @@ dups=$(jq -r '.packages[].id' "$catalog" | sort | uniq -d) echo "ok" echo "== 3. release URLs" -# When a package has a `repo`, every release must be an asset of that repository, as Install and -# Preview require (the loader step installs from file:// copies, which skip this check). +# Every release that isn't a local file:// path must be a release asset, and when its package has +# a `repo`, an asset of that repository, as Install and Preview require (the loader step installs +# from file:// copies, which skip this check). bad=$(jq -r ' # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); + # "owner/name" in lower case of a release asset, + # https://github.com///releases/download// (a tag may contain `/`), with + # no query, fragment, backslash, or empty, `.` or `..` segment; "?" for anything else. + def asset_of: + if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then + .[19:] as $rest + | ($rest | split("/")) as $p + | if ($rest | test("[?#\\\\]")) or ($p | length) < 6 or ($p | any(bad_segment)) + or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not) + or $p[2] != "releases" or $p[3] != "download" + then "?" else "\($p[0])/\($p[1])" | ascii_downcase end + else "?" end; # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") @@ -56,12 +69,13 @@ bad=$(jq -r ' | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) | "\(.o)/\(.n)" | ascii_downcase) // "?"; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo - | select($repo != "") | ($repo | repo_of) as $want + | (if $repo == "" then "" else $repo | repo_of end) as $want | .versions[] | select(.url | startswith("file://") | not) - | ((.url | ascii_downcase | capture("^https://github\\.com/(?[^/]+)/(?[^/]+)/releases/download/") | "\(.o)/\(.n)") // "?") as $got - | select($want == "?" or $got != $want) - | "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)"' "$catalog") -[ -z "$bad" ] || fail "release URLs outside the package's repo:"$'\n'"$bad" + | (.url | asset_of) as $got + | if $got == "?" then "\($pkg.id) \(.version): \(.url) is not a release asset (https://github.com///releases/download//)" + elif $want != "" and ($want == "?" or $got != $want) then "\($pkg.id) \(.version): \(.url) is not a release asset of \($repo)" + else empty end' "$catalog") +[ -z "$bad" ] || fail "release URLs that Install and Preview refuse:"$'\n'"$bad" echo "ok" echo "== 4. downloads" From 36dc209badfdbab2fa99f44e130798e3c35277ef Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 6 Nov 2026 00:49:16 -0800 Subject: [PATCH 06/24] Plug-in Library: release and repo URLs with white space are refused Install and Preview, the catalog schema and scripts/validate.sh now refuse a release URL or repo folder that contains white space in any segment, the tag and file name included: any Unicode white space character, and U+FEFF. Before, the app accepted a space or tab in a tag, file name or repo folder that the schema refused. --- crates/engine/src/system/library.rs | 19 +++++++++++++++++-- examples/plugin-catalog/schema.json | 4 ++-- examples/plugin-catalog/scripts/validate.sh | 9 ++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/system/library.rs b/crates/engine/src/system/library.rs index d1eaaf0bd..8fb147e53 100644 --- a/crates/engine/src/system/library.rs +++ b/crates/engine/src/system/library.rs @@ -272,12 +272,18 @@ fn dot_segment(p: &str) -> bool { p == "." || p == ".." } +/// A character a release or repository URL may not contain: `?`, `#`, `\`, Unicode white space, +/// or U+FEFF (the catalog schema's `\s` matches it too). +fn bad_url_char(c: char) -> bool { + matches!(c, '?' | '#' | '\\' | '\u{feff}') || c.is_whitespace() +} + /// `(owner, name)` in lower case of a `https://github.com//` repository URL (an /// optional trailing `/` or `.git`) or of a folder in one, `https://github.com///tree//`; /// `None` for anything else. fn github_repo(repo: &str) -> Option<(String, String)> { let rest = strip_prefix_ignore_case(repo.trim(), "https://github.com/")?; - if rest.contains(['?', '#', '\\']) { + if rest.contains(bad_url_char) { return None; } let rest = rest.strip_suffix('/').unwrap_or(rest); @@ -296,7 +302,7 @@ fn github_repo(repo: &str) -> Option<(String, String)> { fn release_url_problem(repo: &str, url: &str) -> Option { let not_asset = || Some(format!("`{url}` isn't a release asset (https://github.com///releases/download//)")); let Some(rest) = strip_prefix_ignore_case(url, "https://github.com/") else { return not_asset() }; - if rest.contains(['?', '#', '\\']) { + if rest.contains(bad_url_char) { return not_asset(); } let parts: Vec<&str> = rest.split('/').collect(); @@ -1230,6 +1236,12 @@ mod tests { "https://github.com/me/glow/releases/download/./v1/x.wasm", "https://github.com/me/glow/releases/download/v1\\x.wasm", "https://github.com/m e/glow/releases/download/v1/x.wasm", + "https://github.com/me/glow/releases/download/v 1/x.wasm", + "https://github.com/me/glow/releases/download/v1/x\t.wasm", + "https://github.com/me/glow/releases/download/v1/x.wasm\n", + "https://github.com/me/glow/releases/download/v1\u{a0}/x.wasm", + "https://github.com/me/glow/releases/download/v1/\u{85}x.wasm", + "https://github.com/me/glow/releases/download/v1/x\u{feff}.wasm", "https://github.com/../glow/releases/download/v1/x.wasm", "https://github.com.evil.com/me/glow/releases/download/v1/x.wasm", ] { @@ -1281,6 +1293,9 @@ mod tests { "https://github.com/me/glow?tab=readme", "https://github.com/me/glow#readme", "https://github.com/me/gl ow", + "https://github.com/me/glow/tree/main/my plug-in", + "https://github.com/me/glow/tree/ma\tin", + "https://github.com/me/glow/tree/main/x\u{feff}", "https://github.com/me/..", ] { let why = release_url_problem(repo, asset); diff --git a/examples/plugin-catalog/schema.json b/examples/plugin-catalog/schema.json index 5fe914d86..c31d57fea 100644 --- a/examples/plugin-catalog/schema.json +++ b/examples/plugin-catalog/schema.json @@ -14,7 +14,7 @@ "version": {"type": "string", "maxLength": 32, "pattern": "^[0-9]+(\\.[0-9]+)*$"}, "release_url": { "type": "string", - "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s]+(/[^/?#\\\\\\s]+)+$" + "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))https://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+/releases/download/[^/?#\\\\\\s\\u0085]+(/[^/?#\\\\\\s\\u0085]+)+$" }, "package": { "type": "object", @@ -26,7 +26,7 @@ "author": {"type": "string"}, "description": {"type": "string"}, "license": {"type": "string"}, - "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s]+)+)?/?$"}, + "repo": {"type": "string", "pattern": "^(?!.*/(\\.|%2[eE]){1,2}(/|$))[Hh][Tt][Tt][Pp][Ss]://[Gg][Ii][Tt][Hh][Uu][Bb]\\.[Cc][Oo][Mm]/[A-Za-z0-9._-]+/[A-Za-z0-9._-]+(/tree(/[^/?#\\\\\\s\\u0085]+)+)?/?$"}, "tags": {"type": "array", "items": {"type": "string"}}, "preview": { "type": "object", diff --git a/examples/plugin-catalog/scripts/validate.sh b/examples/plugin-catalog/scripts/validate.sh index 4a0d196fc..711b69394 100644 --- a/examples/plugin-catalog/scripts/validate.sh +++ b/examples/plugin-catalog/scripts/validate.sh @@ -49,25 +49,28 @@ echo "== 3. release URLs" bad=$(jq -r ' # A path segment EffectCraft refuses: empty, `.` or `..` (also percent-encoded). def bad_segment: . == "" or (ascii_downcase | gsub("%2e"; ".") | . == "." or . == ".."); + # A `?`, `#`, `\` or white space character (Unicode, and U+FEFF), which EffectCraft refuses in a URL. + def bad_char: test("[?#\\\\\t\n\u000b\f\r \u0085   - 

   ]"); # "owner/name" in lower case of a release asset, # https://github.com///releases/download// (a tag may contain `/`), with - # no query, fragment, backslash, or empty, `.` or `..` segment; "?" for anything else. + # no query, fragment, backslash, white space, or empty, `.` or `..` segment; "?" for anything else. def asset_of: if startswith("https://") and (.[8:19] | ascii_downcase) == "github.com/" then .[19:] as $rest | ($rest | split("/")) as $p - | if ($rest | test("[?#\\\\]")) or ($p | length) < 6 or ($p | any(bad_segment)) + | if ($rest | bad_char) or ($p | length) < 6 or ($p | any(bad_segment)) or ($p[0] | test("^[A-Za-z0-9._-]+$") | not) or ($p[1] | test("^[A-Za-z0-9._-]+$") | not) or $p[2] != "releases" or $p[3] != "download" then "?" else "\($p[0])/\($p[1])" | ascii_downcase end else "?" end; # Only the scheme, host, owner and name compare without case; the `.git` suffix is lower case. def repo_of: + if bad_char then "?" else (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+?)(\\.git)?/?$") // (capture("^(?[^/]+//[^/]+)/(?[A-Za-z0-9._-]+)/(?[A-Za-z0-9._-]+)/tree/(?[^?#\\\\]+?)/?$") | select(.f | split("/") | any(bad_segment) | not)) | select((.h | ascii_downcase) == "https://github.com" and (.o | bad_segment | not) and (.n | bad_segment | not)) - | "\(.o)/\(.n)" | ascii_downcase) // "?"; + | "\(.o)/\(.n)" | ascii_downcase) // "?" end; .packages[] | . as $pkg | ((.repo // "") | gsub("^\\s+|\\s+$"; "")) as $repo | (if $repo == "" then "" else $repo | repo_of end) as $want | .versions[] | select(.url | startswith("file://") | not) From 1c47f233ea9b18bd74a4eb4a178f406f2896b716 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 12:57:53 +0100 Subject: [PATCH 07/24] Graph Editor: the value curve passes through every key and draws Hold steps vertically Refs #2720 The curve was sampled on an even grid every 2 px, blind to key times. Zoomed out, keys one frame apart sit closer than a sample step, so the polyline cut across the jump instead of passing through the key squares, and a Hold step was drawn as a slope across one step. The samples now also include every visible key time and both sides of the key after a Hold key (so a stretched layer's one-tick rounding or a reversed layer still gives a vertical step). Keys denser than the grid add no samples, so the work stays bounded. This does not change the slanted spans in the issue's screenshot: their key squares sit at different values (about 0.36 vs 0.40, 0.01 vs 0.00), so the curve draws the stored values as they are. --- crates/ui-egui/src/panels/graph.rs | 142 ++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs index be18999d4..8a4401d97 100644 --- a/crates/ui-egui/src/panels/graph.rs +++ b/crates/ui-egui/src/panels/graph.rs @@ -130,6 +130,45 @@ fn speed_at(pr: &Property, spatial: bool, d: usize, lt: Tick) -> f64 { } } +/// How far either side of the key after a Hold key the step is sampled (seconds; far below a +/// pixel, far above the tick a stretched layer's time conversion can be off by). +const HOLD_EDGE: f64 = 1e-6; + +/// The comp times (seconds) a curve is sampled at between `t0` and `t1`: `n` evenly spaced +/// times, plus every key time `keys` puts inside the span, and around the key after a key that +/// holds (its out side is Hold) the instants just before and after it. `keys` are the active +/// keys in key order, as (comp seconds, holds); on a reversed layer their comp times descend. +/// Without the key times the polyline only passes near the keys: keys closer together than a +/// sample step (a one-frame jump zoomed out) got cut across, missing their squares, and a Hold +/// step was drawn as a slope across one step instead of a vertical edge (#2720). With no keys +/// this is the plain even grid. Keys denser than the grid (baked keys zoomed out) add nothing +/// visible and would multiply the evaluations, so past `2 * n` key samples only the grid is used. +fn sample_times(t0: f64, t1: f64, n: usize, keys: &[(f64, bool)]) -> Vec { + let n = n.max(2); + let mut ts: Vec = (0..n).map(|i| t0 + (t1 - t0) * i as f64 / (n - 1) as f64).collect(); + let (lo, hi) = (t0.min(t1), t0.max(t1)); + let inside = |t: f64| t > lo && t < hi; + let max_extra = n.saturating_mul(2); + let mut extra = vec![]; + for (i, &(kt, holds)) in keys.iter().enumerate() { + if inside(kt) { + extra.push(kt); + } + if holds && let Some(&(next, _)) = keys.get(i + 1) { + extra.extend([next - HOLD_EDGE, next + HOLD_EDGE].into_iter().filter(|&t| inside(t))); + } + if extra.len() > max_extra { + extra.clear(); + break; + } + } + ts.extend(extra); + ts.retain(|t| t.is_finite()); + ts.sort_by(f64::total_cmp); + ts.dedup(); + ts +} + /// Build the curves for the visible time span. fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, plot: Rect, speed: bool) -> Vec> { let sel = &app.session.state.selected_keys; @@ -140,12 +179,14 @@ fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, pl let Some(pr) = l.props.find(uid) else { continue }; let spatial = pr.spatial && matches!(pr.value, Value::Vec2(_) | Value::Vec3(_)); let dims = if speed && spatial { 1 } else { shown_dims(l, pr) }; + // The active keys (muted ones are skipped by evaluation) in comp seconds, and whether each + // holds its value up to the next one. + let active: Vec<(f64, bool)> = pr.keys.iter().filter(|k| !k.muted).map(|k| (l.comp_time(k.time).seconds(), k.out_interp == Interp::Hold)).collect(); + let times = sample_times(tm.t(plot.min.x), tm.t(plot.max.x), n, &active); for d in 0..dims { let color = if dims > 1 { DIM_COLORS[d % 4] } else { PROP_COLORS[pi % PROP_COLORS.len()] }; - let mut pts = Vec::with_capacity(n); - for i in 0..n { - let x = plot.min.x + plot.width() * i as f32 / (n - 1) as f32; - let ct = tm.t(x); + let mut pts = Vec::with_capacity(times.len()); + for &ct in × { let tt = Tick::from_seconds_f64(ct); let v = if speed { speed_at(pr, spatial, d, l.layer_time(tt)) } else { ectx.at(tt).value(l, pr).components().get(d).copied().unwrap_or(0.0) }; pts.push((ct, v)); @@ -892,7 +933,98 @@ fn shift_axes(shift: bool, dx: f32, dy: f32) -> (bool, bool) { #[cfg(test)] mod tests { - use super::shift_axes; + use super::{HOLD_EDGE, sample_times, shift_axes}; + use effectcraft_engine::keyframe::{Keyframe, Value, evaluate}; + use effectcraft_engine::time::Tick; + + /// The value-graph polyline of `keys` (layer time = comp time) sampled at `times`. + fn polyline(keys: &[Keyframe], times: &[f64]) -> Vec<(f64, f64)> { + times + .iter() + .map(|&t| { + let v = evaluate(keys, Tick::from_seconds_f64(t), false).map(|v| v.components().first().copied().unwrap_or(f64::NAN)).unwrap_or(f64::NAN); + (t, v) + }) + .collect() + } + + fn active(keys: &[Keyframe]) -> Vec<(f64, bool)> { + keys.iter().map(|k| (k.time.seconds(), k.out_interp == effectcraft_engine::keyframe::Interp::Hold)).collect() + } + + /// #2720: a step one frame wide, zoomed out so it is narrower than a sample step. The curve + /// has to pass through every key square: the old even grid (`sample_times` with no keys) + /// never sampled 0.2 s or 0.2 s + 1 frame and drew a slope from 0 to 1 across the step. + #[test] + fn value_graph_passes_through_keys_narrower_than_a_sample_step() { + let keys = [ + Keyframe::new(Tick::from_seconds_f64(0.0), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2), Value::Scalar(0.0)), + Keyframe::new(Tick::from_seconds_f64(0.2 + 1.0 / 30.0), Value::Scalar(1.0)), + Keyframe::new(Tick::from_seconds_f64(0.9), Value::Scalar(1.0)), + ]; + let times = sample_times(0.0, 1.0, 4, &active(&keys)); + let pts = polyline(&keys, ×); + for k in &keys { + let (t, v) = (k.time.seconds(), k.value.components()[0]); + assert!(pts.iter().any(|p| p.0 == t && (p.1 - v).abs() < 1e-12), "no curve point on the key at {t} s ({v}): {pts:?}"); + } + // The spans between equal keys are flat: no sample between 0 and 0.2 s leaves 0, none + // between 0.2 s + 1 frame and 0.9 s leaves 1. + for &(t, v) in &pts { + if t <= 0.2 { + assert!(v.abs() < 1e-12, "{t} s: {v}"); + } else if (0.2 + 1.0 / 30.0..=0.9).contains(&t) { + assert!((v - 1.0).abs() < 1e-12, "{t} s: {v}"); + } + } + // Times are sorted and unique, the even grid is still there. + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + assert!([0.0, 1.0 / 3.0, 2.0 / 3.0, 1.0].iter().all(|g| times.iter().any(|t| (t - g).abs() < 1e-12)), "{times:?}"); + } + + /// #2720: a Hold key draws a vertical step at the next key, not a slope across a sample step. + #[test] + fn hold_step_is_vertical() { + let keys = [Keyframe::new(Tick::from_seconds_f64(0.1), Value::Scalar(0.0)).hold(), Keyframe::new(Tick::from_seconds_f64(0.5), Value::Scalar(1.0))]; + let pts = polyline(&keys, &sample_times(0.0, 1.0, 4, &active(&keys))); + let at = pts.iter().position(|p| p.0 == 0.5).unwrap_or_else(|| panic!("no sample on the key at 0.5 s: {pts:?}")); + let before = pts[at - 1]; + assert!((0.5 - before.0 - HOLD_EDGE).abs() < 1e-12 && before.1.abs() < 1e-12, "the held value ends right before the next key: {pts:?}"); + assert!((pts[at].1 - 1.0).abs() < 1e-12, "{pts:?}"); + } + + #[test] + fn sample_times_keep_keys_inside_the_span_only() { + let times = sample_times(1.0, 2.0, 3, &[(0.5, true), (1.25, false), (2.5, false)]); + // 0.5 s and 2.5 s are off screen; the hold from 0.5 s ends at 1.25 s, inside it. + assert_eq!(times, vec![1.0, 1.25 - HOLD_EDGE, 1.25, 1.25 + HOLD_EDGE, 1.5, 2.0]); + // Degenerate input never panics: an empty span is one point, a NaN span has no points. + assert_eq!(sample_times(0.0, 0.0, 0, &[]), vec![0.0]); + assert!(sample_times(f64::NAN, 1.0, 4, &[(0.5, true)]).iter().all(|t| t.is_finite())); + } + + /// A reversed layer: its keys run backwards in comp time, and both sides of each step after + /// a Hold key are still sampled. + #[test] + fn sample_times_cover_hold_steps_on_a_reversed_layer() { + let times = sample_times(1.0, 2.0, 10, &[(1.8, true), (1.4, true), (1.1, false)]); + for t in [1.8, 1.4 - HOLD_EDGE, 1.4, 1.4 + HOLD_EDGE, 1.1 - HOLD_EDGE, 1.1, 1.1 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing: {times:?}"); + } + assert!(times.windows(2).all(|w| w[0] < w[1]), "{times:?}"); + } + + /// Dense keys zoomed out (100 000 in one second, half of them Hold) don't multiply the samples. + #[test] + fn sample_times_stay_bounded_with_dense_keys() { + let keys: Vec<(f64, bool)> = (0..100_000).map(|i| (i as f64 / 100_000.0, i % 2 == 0)).collect(); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 300, "{} samples", times.len()); + // A few keys inside the span are still all sampled. + let few = sample_times(0.0, 1.0, 100, &keys[..50]); + assert!(keys[1..50].iter().all(|(t, _)| few.contains(t)), "{few:?}"); + } #[test] fn shift_locks_drag_to_dominant_axis() { From 36854318db1bbd8a2d1eafacb1efc5611fba8422 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 14:02:20 +0100 Subject: [PATCH 08/24] Viewer: the Rotation tool counts the turn from the press The Rotation gesture seeded its angle from the pointer where egui registered the drag, past the drag threshold, so the sweep round the anchor before that was lost; near the anchor that is a large angle. Count from where the button went down, as After Effects does and as the Create and Pan Behind gestures already do. A press within 3 points of the anchor, or with no anchor on screen, has no direction and still counts from where the drag registered, so the first move doesn't jump. The layer under the press is the one picked. The issue's main cause, a pivot far off for child and 3D layers, was fixed by #2887. Refs #2769 --- crates/ui-egui/src/panels/viewer.rs | 13 ++++-- crates/ui-egui/tests/it/ui_viewer.rs | 61 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/viewer.rs b/crates/ui-egui/src/panels/viewer.rs index b1899e1f8..f17d11795 100644 --- a/crates/ui-egui/src/panels/viewer.rs +++ b/crates/ui-egui/src/panels/viewer.rs @@ -1193,16 +1193,23 @@ fn phase_dragstart(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, }) } Tool::MaskFeather => ov::begin_feather(app, ectx, &paths, &map, press).map(Gesture::Overlay), - Tool::Rotate => pick(app, ectx, cpt, mods.shift).map(|l| { + // The layer under the press is the one that turns. + Tool::Rotate => pick(app, ectx, map.to_comp(press), mods.shift).map(|l| { let layer = comp.layer(l).cloned(); let sign = layer.as_ref().map_or(1.0, |l| rotation_sign(ectx, l)); let others = selected_others(app, comp, l) .into_iter() .filter_map(|o| Some((o.id, ectx.f(o, o.transform()?, "rotation", 0.0), rotation_sign(ectx, o) * sign))) .collect(); - let pivot = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)).unwrap_or(cpt); + let anchor = layer.as_ref().and_then(|l| anchor_in_comp(ectx, l)); + let pivot = anchor.unwrap_or(cpt); let rot = layer.as_ref().and_then(|l| l.transform().map(|tr| ectx.f(l, tr, "rotation", 0.0))).unwrap_or(0.0); - let last_angle = (cpt[1] - pivot[1]).atan2(cpt[0] - pivot[0]).to_degrees(); + // The turn counts from where the button went down, as in After Effects: by the + // time the drag registers the pointer has already swept some way round the anchor. + // A press on the anchor (or with no anchor to turn about) has no direction, so + // the turn then counts from where the drag registered. + let seed = if anchor.is_some() && press.distance(map.to_screen(pivot)) > 3.0 { map.to_comp(press) } else { cpt }; + let last_angle = (seed[1] - pivot[1]).atan2(seed[0] - pivot[0]).to_degrees(); Gesture::Rotate { layer: l, pivot, sign, last_angle, turned: 0.0, start_rot: rot, others } }), Tool::PanBehind => pick(app, ectx, cpt, false).and_then(|l| { diff --git a/crates/ui-egui/tests/it/ui_viewer.rs b/crates/ui-egui/tests/it/ui_viewer.rs index 7b32fa2ec..bd047088b 100644 --- a/crates/ui-egui/tests/it/ui_viewer.rs +++ b/crates/ui-egui/tests/it/ui_viewer.rs @@ -3022,6 +3022,67 @@ fn rotate_tool_counts_revolutions_both_ways() { assert_eq!(h.state().session.history.undo.len(), undo_before + 1, "one drag, one undo step"); } +/// #2769: the Rotation tool counts the turn from where the button went down, as in After Effects, +/// not from where the drag registered: a first move that sweeps 60° round the anchor turns the +/// layer 60° (it used to drop that sweep, so near the anchor the tool lagged behind the pointer). +#[test] +fn rotate_tool_counts_the_turn_from_the_press() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + // Press on the box right of its anchor (0°), then one move to 60° clockwise, still on the box. + let press = center + vec2(r * 0.3, 0.0); + let to = center + vec2(r * 60f32.to_radians().cos(), r * 60f32.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(press)); + h.input_mut().events.push(Event::PointerButton { pos: press, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(to)); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + h.input_mut().events.push(Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); + let rot = h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64(); + assert!((rot - 60.0).abs() < 1.0, "the whole sweep from the press turns the layer: {rot}"); +} + +/// #2769: a press right on the anchor point has no direction to count the turn from, so the layer +/// doesn't jump on the first move; the turn counts from where the drag registered. +#[test] +fn rotate_tool_pressed_on_the_anchor_does_not_jump() { + let mut h = harness(); + let box_id = h.state().session.active_comp().unwrap().layers[0].id; + h.state_mut().session.execute("layer.select", json!({"layers": [box_id.0]})).unwrap(); + h.state_mut().ui.tool = Tool::Rotate; + h.run_steps(2); + let rotation = |h: &Harness<'_, EffectcraftApp>| { + h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/rotation").unwrap().value.as_f64() + }; + let center = screen(&h, [320.0, 180.0]); + let r = (screen(&h, [350.0, 180.0]) - center).x; + let at = |deg: f32| center + vec2(r * deg.to_radians().cos(), r * deg.to_radians().sin()); + h.input_mut().events.push(Event::PointerMoved(center)); + h.input_mut().events.push(Event::PointerButton { pos: center, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); + h.step(); + h.input_mut().events.push(Event::PointerMoved(at(60.0))); + h.step(); + // The gesture applies the previous frame's pointer: hold a frame. + h.step(); + let first = rotation(&h); + assert!(first.abs() < 1.0, "no jump on the first move: {first}"); + h.input_mut().events.push(Event::PointerMoved(at(90.0))); + h.step(); + h.step(); + let next = rotation(&h); + assert!((next - 30.0).abs() < 1.0, "then turns with the pointer: {next}"); + h.input_mut().events.push(Event::PointerButton { pos: at(90.0), button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); + h.run_steps(2); +} + /// A harness whose Box is a child of Plate (anchor 320,180) with `plate` set on Plate first, at /// parent-space position (200, 120). Returns the two layers' ids. fn rotate_child_harness(plate: serde_json::Value) -> (Harness<'static, EffectcraftApp>, u64, u64) { From e109fa6b95310ac84955bef6b272c0c76aa2e2c3 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 15:20:11 +0100 Subject: [PATCH 09/24] Graph Editor: a dense key cluster only thins its own grid steps Refs #2720 When the key samples passed the budget, sample_times dropped all of them, so a sparse Hold step elsewhere in view went back to a slope. Key samples are now kept per grid step: up to four as they are, past that only the earliest and latest of that step. Sparse keys keep every sample and a curve still has at most 5 * n samples. --- crates/ui-egui/src/panels/graph.rs | 87 +++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/panels/graph.rs b/crates/ui-egui/src/panels/graph.rs index 8a4401d97..397d9cab3 100644 --- a/crates/ui-egui/src/panels/graph.rs +++ b/crates/ui-egui/src/panels/graph.rs @@ -134,6 +134,42 @@ fn speed_at(pr: &Property, spatial: bool, d: usize, lt: Tick) -> f64 { /// pixel, far above the tick a stretched layer's time conversion can be off by). const HOLD_EDGE: f64 = 1e-6; +/// How many key samples one grid step of [`sample_times`] keeps as they are (a key and both +/// sides of a Hold step fit); past that only its earliest and latest are kept. +const BUCKET_KEEP: usize = 4; + +/// The key samples falling in one grid step of [`sample_times`]. +#[derive(Clone)] +struct Bucket { + few: Vec, + first: f64, + last: f64, + /// More than [`BUCKET_KEEP`] samples fell here. + full: bool, +} + +impl Default for Bucket { + fn default() -> Self { + Bucket { few: Vec::new(), first: f64::INFINITY, last: f64::NEG_INFINITY, full: false } + } +} + +impl Bucket { + fn add(&mut self, t: f64) { + self.first = self.first.min(t); + self.last = self.last.max(t); + if self.full { + return; + } + if self.few.len() < BUCKET_KEEP { + self.few.push(t); + } else { + self.full = true; + self.few = Vec::new(); + } + } +} + /// The comp times (seconds) a curve is sampled at between `t0` and `t1`: `n` evenly spaced /// times, plus every key time `keys` puts inside the span, and around the key after a key that /// holds (its out side is Hold) the instants just before and after it. `keys` are the active @@ -142,27 +178,40 @@ const HOLD_EDGE: f64 = 1e-6; /// sample step (a one-frame jump zoomed out) got cut across, missing their squares, and a Hold /// step was drawn as a slope across one step instead of a vertical edge (#2720). With no keys /// this is the plain even grid. Keys denser than the grid (baked keys zoomed out) add nothing -/// visible and would multiply the evaluations, so past `2 * n` key samples only the grid is used. +/// visible and would multiply the evaluations: in a grid step with more than [`BUCKET_KEEP`] +/// key samples only the earliest and latest are kept, so a curve has at most `5 * n` samples +/// and sparse keys elsewhere in view keep every sample. fn sample_times(t0: f64, t1: f64, n: usize, keys: &[(f64, bool)]) -> Vec { let n = n.max(2); let mut ts: Vec = (0..n).map(|i| t0 + (t1 - t0) * i as f64 / (n - 1) as f64).collect(); let (lo, hi) = (t0.min(t1), t0.max(t1)); let inside = |t: f64| t > lo && t < hi; - let max_extra = n.saturating_mul(2); - let mut extra = vec![]; + // One bucket per grid step. + let steps = n - 1; + let mut buckets = vec![Bucket::default(); steps]; + let mut add = |t: f64| { + if !inside(t) { + return; + } + let b = (((t - lo) / (hi - lo) * steps as f64) as usize).min(steps - 1); + if let Some(bucket) = buckets.get_mut(b) { + bucket.add(t); + } + }; for (i, &(kt, holds)) in keys.iter().enumerate() { - if inside(kt) { - extra.push(kt); - } + add(kt); if holds && let Some(&(next, _)) = keys.get(i + 1) { - extra.extend([next - HOLD_EDGE, next + HOLD_EDGE].into_iter().filter(|&t| inside(t))); + add(next - HOLD_EDGE); + add(next + HOLD_EDGE); } - if extra.len() > max_extra { - extra.clear(); - break; + } + for b in &buckets { + if b.full { + ts.extend([b.first, b.last]); + } else { + ts.extend_from_slice(&b.few); } } - ts.extend(extra); ts.retain(|t| t.is_finite()); ts.sort_by(f64::total_cmp); ts.dedup(); @@ -1021,9 +1070,19 @@ mod tests { let keys: Vec<(f64, bool)> = (0..100_000).map(|i| (i as f64 / 100_000.0, i % 2 == 0)).collect(); let times = sample_times(0.0, 1.0, 100, &keys); assert!(times.len() <= 300, "{} samples", times.len()); - // A few keys inside the span are still all sampled. - let few = sample_times(0.0, 1.0, 100, &keys[..50]); - assert!(keys[1..50].iter().all(|(t, _)| few.contains(t)), "{few:?}"); + } + + /// A dense cluster of keys only thins its own grid steps: a Hold step elsewhere in view keeps + /// its key and both sides of the step. + #[test] + fn sample_times_keep_sparse_keys_beside_a_dense_cluster() { + let mut keys: Vec<(f64, bool)> = (0..100_000).map(|i| (0.1 * i as f64 / 100_000.0, i % 2 == 0)).collect(); + keys.extend([(0.5, true), (0.8, false)]); + let times = sample_times(0.0, 1.0, 100, &keys); + assert!(times.len() <= 500, "{} samples", times.len()); + for t in [0.5, 0.8 - HOLD_EDGE, 0.8, 0.8 + HOLD_EDGE] { + assert!(times.contains(&t), "{t} missing"); + } } #[test] From 2d547200c02dc612ce6b125f3ea395430bdb55f7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 16:13:20 +0100 Subject: [PATCH 10/24] Effect Controls: Alt-click on a stopwatch adds an expression and edits it in the Timeline Refs #1460. As in After Effects, Alt-click (Option-click) on a stopwatch in Effect Controls adds an expression (it toggled keyframing instead) and Alt-click again removes it. Effect Controls has no expression field, so the property is revealed in the Timeline (the same reveal as a double-click on its name, #1497) and the new expression's editor takes the keyboard with the expression selected. The Timeline's stopwatch and Effect Controls share one helper for that focus request (expression_toggled). The editor takes a request from the pass after the one it was made in: drawn in the same pass as the Alt-click in another panel, its text field gave the keyboard straight back as a click elsewhere. --- .../src/panels/effect_controls/rows.rs | 30 +++++++++--- crates/ui-egui/src/panels/timeline.rs | 33 +++++++++---- crates/ui-egui/tests/it/ui_inline_edit.rs | 48 +++++++++++++++++++ 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/crates/ui-egui/src/panels/effect_controls/rows.rs b/crates/ui-egui/src/panels/effect_controls/rows.rs index c14630af4..e7f1bfee5 100644 --- a/crates/ui-egui/src/panels/effect_controls/rows.rs +++ b/crates/ui-egui/src/panels/effect_controls/rows.rs @@ -128,6 +128,18 @@ impl PropCx<'_> { } } +/// Shows property `uid` of layer `layer` in the Timeline: its layer and groups twirled open, the +/// property scrolled to and the Timeline brought forward (After Effects' Reveal in Timeline, +/// which a double-click on the property's name does; #1497). +fn reveal_in_timeline(app: &mut EffectcraftApp, ctx: &egui::Context, layer: u64, uid: u64) { + app.ui.timeline.search.clear(); + app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); + if let Err(e) = crate::menus::frontend(app, ctx, "timeline.revealProps", json!({"props": [{"layer": layer, "prop": uid}]})) { + app.ui.status = e; + } + app.show_panel(crate::dock::PanelKind::Timeline); +} + /// One property row: stopwatch, name, value control (and the keyframe navigator). Returns the /// value fields of a vector, one per dimension, for the pick whip. #[allow(clippy::too_many_arguments)] @@ -167,7 +179,16 @@ fn prop_row( }, ); app.auto.add(&format!("effectControls.prop.{uid}.stopwatch"), swr, &prop.name); - if resp.clicked() { + if resp.clicked() && ui.input(|i| i.modifiers.alt) { + // Alt+click adds an expression (or removes it), as in the Timeline. Effect Controls + // has no expression field: the property shows in the Timeline with its new + // expression's editor taking the keyboard, as After Effects does (#1460). + actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid}))); + if prop.expr.is_none() { + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); + } + crate::panels::timeline::expression_toggled(app, ui.ctx(), prop); + } else if resp.clicked() { actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "selected": true}))); } } @@ -201,12 +222,7 @@ fn prop_row( p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text); let name_response = ui.interact(name_clip, egui::Id::unique(("ec-prop-name", uid)), Sense::click()); if name_response.double_clicked() { - app.ui.timeline.search.clear(); - app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid)); - if let Err(e) = crate::menus::frontend(app, ui.ctx(), "timeline.revealProps", json!({"props": [{"layer": layer.id.0, "prop": uid}]})) { - app.ui.status = e; - } - app.show_panel(crate::dock::PanelKind::Timeline); + reveal_in_timeline(app, ui.ctx(), layer.id.0, uid); } app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name); // With several layers selected the edit applies to the same effect property of each (#491). diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 038dcc9b9..e7f8311c0 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -323,9 +323,27 @@ fn expr_focus_id() -> egui::Id { egui::Id::unique("tl-expr-focus") } +/// Asks the expression editor of property `prop` to take the keyboard when the Timeline next +/// draws it, selecting `select` (counts of characters before the end). fn focus_expression(ctx: &egui::Context, prop: u64, select: [usize; 2]) { let pass = ctx.cumulative_pass_nr(); ctx.data_mut(|d| d.insert_temp(expr_focus_id(), ExprFocus { prop, select, pass })); + // The editor takes it in a later pass: make sure one comes without waiting for input. + ctx.request_repaint(); +} + +/// After a `prop.setExpression` toggle of `prop` was queued (an Alt-click on its stopwatch, in the +/// Timeline or in Effect Controls): adding one, its editor opens, comes into view and takes the +/// keyboard with the new expression selected (#1072, #1460); removing it, a pending request for +/// its editor goes, as nothing is left to take the keyboard. +pub(crate) fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { + let uid = prop.uid; + if prop.expr.is_none() { + app.ui.timeline.expr_closed.remove(&uid); + focus_expression(ctx, uid, [usize::MAX, 0]); + } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { + ctx.data_mut(|d| d.remove::(expr_focus_id())); + } } #[derive(Clone, Debug)] @@ -3927,7 +3945,10 @@ fn expr_editor_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg); let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0)); let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone()); - if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid) { + // Not in the pass it was asked for in: a click that asked for it from another panel (an + // Alt-click on a stopwatch in Effect Controls, drawn before the Timeline) would take the + // keyboard straight back as a click elsewhere (#1460). + if let Some(f) = ctx.data(|d| d.get_temp::(expr_focus_id())).filter(|f| f.prop == *uid && ctx.cumulative_pass_nr() > f.pass) { // Asked for once (a pick whip put a reference in, or an Alt-click added the // expression): editing starts in the expression as it is now. ctx.data_mut(|d| d.remove::(expr_focus_id())); @@ -4079,15 +4100,7 @@ fn prop_stopwatch(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: & if ui.input(|i| i.modifiers.alt) { if resp.clicked() { actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid}))); - if prop.expr.is_none() { - // Adding one: its editor opens, comes into view and takes the - // keyboard with the new expression selected (#1072). - app.ui.timeline.expr_closed.remove(uid); - focus_expression(&ctx, *uid, [usize::MAX, 0]); - } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == *uid) { - // Removing it: nothing is left to take the keyboard. - ctx.data_mut(|d| d.remove::(expr_focus_id())); - } + expression_toggled(app, &ctx, prop); } } else if let Some((value, merge)) = switch_gesture(ui, &resp, r, "stopwatch", prop.is_animated()) { actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "value": value, "merge": merge}))); diff --git a/crates/ui-egui/tests/it/ui_inline_edit.rs b/crates/ui-egui/tests/it/ui_inline_edit.rs index 6c29045bb..8271e2f9e 100644 --- a/crates/ui-egui/tests/it/ui_inline_edit.rs +++ b/crates/ui-egui/tests/it/ui_inline_edit.rs @@ -634,6 +634,54 @@ fn an_expression_added_at_the_bottom_of_the_timeline_comes_into_view() { assert_eq!(expression(&h, layer, opacity).as_deref(), Some("25")); } +/// #1460: Alt-clicking an effect property's stopwatch in Effect Controls adds an expression, as in +/// the Timeline (it toggled the animation instead). Effect Controls has no expression field, so, +/// as in After Effects, the property shows in the Timeline (its layer and effect twirled open, +/// scrolled into view) with the new expression's editor taking the keyboard: typing replaces +/// it. Another Alt-click removes it and leaves nothing holding the keyboard. +#[test] +fn alt_clicking_a_stopwatch_in_effect_controls_edits_the_expression_in_the_timeline() { + let (mut h, _) = harness(); + let (layer, slider) = { + let s = &mut h.state_mut().session; + let l = s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap()["layer"].as_u64().unwrap(); + s.execute("effect.apply", json!({"layers": [l], "effect": "Slider Control"})).unwrap(); + // Layers above push it below the bottom of the Timeline. + for i in 0..40 { + s.execute("layer.newSolid", json!({"name": format!("Layer {i}"), "color": "#204060"})).unwrap(); + } + s.execute("layer.select", json!({"layers": [l]})).unwrap(); + let slider = s.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(l)).unwrap().props.prop("effects/#1/slider").unwrap().uid; + (l, slider) + }; + h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::EffectControls); + h.run_steps(3); + let editor = format!("timeline.prop.{slider}.expression"); + assert!(h.state().auto.find(&format!("timeline.prop.{slider}.row")).is_none(), "the property is not in the Timeline yet"); + let alt = Modifiers { alt: true, ..Modifiers::NONE }; + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + assert!(expression(&h, layer, slider).is_some(), "an expression was added"); + let key = h.state().session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(layer)).unwrap().props.find(slider).unwrap().is_animated(); + assert!(!key, "Alt-click doesn't turn on keyframing"); + assert!(h.state().ui.timeline.reveal_props.contains(&slider), "the property is revealed in the Timeline"); + let rows = h.state().auto.find("timeline.scroll").expect("the Timeline is shown").rect; + let e = h.state().auto.find(&editor).expect("the Timeline draws the expression editor").rect; + assert!(e[1] >= rows[1] - 0.5 && e[1] + e[3] <= rows[1] + rows[3] + 0.5, "the editor is in view: {e:?} in {rows:?}"); + type_text(&mut h, "42"); + commit_expression(&mut h); + assert_eq!(expression(&h, layer, slider).as_deref(), Some("42"), "typing replaced the new expression"); + // Alt-click again removes the expression and its editor with it (the keyboard stays free; + // the editor's focus request was taken when it was added, so this doesn't exercise the + // cancel path). + let at = center(&h, &format!("effectControls.prop.{slider}.stopwatch")); + click_with(&mut h, at, alt); + h.run_steps(5); + assert_eq!(expression(&h, layer, slider), None); + assert!(h.state().auto.find(&editor).is_none(), "the expression editor is gone"); + assert!(!h.ctx.egui_wants_keyboard_input(), "nothing has the keyboard"); +} + /// A primary-button drag from `from` to `to` with `modifiers` held from the press to the release. fn drag_with(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2, modifiers: Modifiers) { h.input_mut().events.push(Event::PointerMoved(from)); From 932326ced681040605017ee064fdbef0d4805fe1 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 7 Nov 2026 19:50:44 +0100 Subject: [PATCH 11/24] Doc comments for the functions this PR touches --- crates/ui-egui/src/panels/viewer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/panels/viewer.rs b/crates/ui-egui/src/panels/viewer.rs index f17d11795..cc3666d6a 100644 --- a/crates/ui-egui/src/panels/viewer.rs +++ b/crates/ui-egui/src/panels/viewer.rs @@ -1130,6 +1130,7 @@ fn led_by_a_moved_ancestor(comp: &Comp, layers: &[MoveLayer]) -> Vec { layers.iter().map(|l| led(l.0)).collect() } +/// Starts the viewer drag gesture for the active tool from the press point, picking the layer, vertex or handle under it. fn phase_dragstart(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, resp: &egui::Response, v: &mut Vw<'_>) { let comp_rect = v.comp_rect; let zoom = v.zoom; From ca4d8470beeab3e2ca2221514790f03f9bb9c56f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 8 Nov 2026 23:54:01 -0800 Subject: [PATCH 12/24] Updates: the first start after an update shows how it ended The check at start sets the status to Updated or InstallFailed, and the result dialog showed only after a Help > Check for Updates request. A failed installation was not reported at start when no newer release was found, and a later manual check replaced the status. The dialog now shows whenever the updater's status is not idle. --- crates/ui-egui/src/lifecycle_tests.rs | 23 +++++++++++++++++++++++ crates/ui-egui/src/updates_ui.rs | 14 ++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/lifecycle_tests.rs b/crates/ui-egui/src/lifecycle_tests.rs index 6c9eb85d2..a6c8115bf 100644 --- a/crates/ui-egui/src/lifecycle_tests.rs +++ b/crates/ui-egui/src/lifecycle_tests.rs @@ -239,6 +239,29 @@ fn the_close_guard_answers_a_close_request_without_a_pass() { assert_eq!(app.ui_passes(), 0); } +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn the_update_result_dialog_shows_every_status_but_idle() { + use craft_update::updater::Status; + let shown = [ + Status::Checking, + Status::UpToDate, + Status::Failed("offline".into()), + Status::Installing, + Status::Ready, + Status::Managed, + Status::Updated("1.2.3".into()), + Status::InstallFailed("access denied".into()), + ]; + for status in &shown { + assert!(updates_ui::result_window_open(false, status, false), "{status:?} opens the dialog without a requested check"); + } + assert!(!updates_ui::result_window_open(false, &Status::Idle, false)); + assert!(!updates_ui::result_window_open(true, &Status::Idle, false), "a check that found a release closes it"); + assert!(updates_ui::result_window_open(true, &Status::Idle, true), "a queued check keeps it open"); + assert!(!updates_ui::result_window_open(false, &Status::Idle, true), "a queued check does not open it"); +} + // ---------------------------------------------------------------- screenshots fn screenshot_request(app: &mut EffectcraftApp, ctx: &egui::Context, path: Option<&str>, target: ShotTarget) -> std::sync::mpsc::Receiver { diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 316e34ac4..e1c4c2eac 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -72,6 +72,15 @@ pub(crate) fn tick(app: &mut EffectcraftApp, ctx: &egui::Context) { let _ = (app, ctx); } +/// Whether the check result dialog shows this frame. It answers Help ▸ Check for Updates until the +/// requested check ends, and it shows whenever the status is not idle: at the first start after an +/// update, the check at start leaves `Updated` or `InstallFailed`. A check that finds a release +/// leaves the status idle and the startup prompt takes over, so the dialog closes then. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn result_window_open(open: bool, status: &Status, check_requested: bool) -> bool { + !matches!(status, Status::Idle) || (open && check_requested) +} + pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { #[cfg(not(target_arch = "wasm32"))] { @@ -83,6 +92,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { Action::None => {} } let rt = &mut app.updates_rt; + rt.manual_window_open = result_window_open(rt.manual_window_open, rt.updater.status(), rt.check_requested); if rt.manual_window_open { match CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).show(ctx, rt.updater.status()) { CheckResultResponse::None => {} @@ -93,10 +103,6 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), } - // A check that found a release leaves the status idle and the startup prompt takes over. - if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested { - rt.manual_window_open = false; - } } } From a31af8b4233d796adb608065d4e4b3ef2f2f689c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 9 Nov 2026 00:08:40 -0800 Subject: [PATCH 13/24] Updates: Restart to Update with unsaved changes opens the save prompt The updater closes the app only when nothing is unsaved, and the result dialog is modal, so with a dirty project Restart to Update did nothing the user could see and the project could not be saved behind the dialog. With unsaved changes the button now closes the result dialog and asks the window to close, which opens the unsaved-changes prompt. Cancel leaves the update ready and a later save does not close the app. When the startup prompt is open, the result dialog closes and the prompt keeps its own Restart to Update. --- crates/ui-egui/src/lifecycle_tests.rs | 54 +++++++++++++++++++++++++++ crates/ui-egui/src/updates_ui.rs | 24 +++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/lifecycle_tests.rs b/crates/ui-egui/src/lifecycle_tests.rs index 6c9eb85d2..ce230f54c 100644 --- a/crates/ui-egui/src/lifecycle_tests.rs +++ b/crates/ui-egui/src/lifecycle_tests.rs @@ -224,6 +224,60 @@ fn workspace_layout_autosave_writes_on_a_hidden_tick() { assert_eq!(app.ui_passes(), 0); } +/// Whether a frame running `f` asked the root window to close. +#[cfg(not(target_arch = "wasm32"))] +fn asks_to_close(ctx: &egui::Context, mut f: impl FnMut(&egui::Context)) -> bool { + let mut out = ctx.run_ui(raw(egui::vec2(800.0, 480.0)), |ui| f(ui.ctx())); + out.textures_delta.clear(); + out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.commands.contains(&egui::ViewportCommand::Close)) +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() { + let ctx = egui::Context::default(); + let frame = eframe::Frame::_new_kittest(); + let mut app = app_with_comp(); + assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes"); + app.updates_rt.manual_window_open = true; + assert!(asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the window is asked to close"); + assert!(!app.updates_rt.manual_window_open, "the modal result dialog closes"); + let mut raw = raw(egui::vec2(800.0, 480.0)); + raw.viewports.insert(egui::ViewportId::ROOT, egui::ViewportInfo { events: vec![egui::ViewportEvent::Close], ..Default::default() }); + let out = tick_with(&mut app, &ctx, &frame, &raw); + assert!(app.dialog.is_some(), "the close opens the unsaved-changes prompt"); + assert!(out.viewport_commands.values().flatten().any(|c| matches!(c, egui::ViewportCommand::CancelClose))); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, true))); + assert!(app.updates_rt.manual_window_open, "the result dialog stays until the updater closes the app"); +} + +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() { + let ctx = egui::Context::default(); + let mut app = app_with_comp(); + app.updates_rt.updater.offer(craft_update::Release { + tag: "v99.0.0".into(), + version: craft_update::parse_version("99.0.0"), + name: "EffectCraft 99.0.0".into(), + html_url: "https://github.com/storytold/effectcraft/releases/tag/v99.0.0".into(), + ..Default::default() + }); + assert!(app.updates_rt.updater.prompt_open()); + app.updates_rt.manual_window_open = true; + assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the prompt carries the restart"); + assert!(!app.updates_rt.manual_window_open, "the result dialog closes"); + assert!(app.updates_rt.updater.prompt_open(), "the prompt stays"); +} + #[test] fn the_close_guard_answers_a_close_request_without_a_pass() { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index 316e34ac4..a4dba938a 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -9,7 +9,7 @@ use craft_update::updater::{Action, Status, Updater}; pub(crate) struct Runtime { #[cfg(not(target_arch = "wasm32"))] - updater: Updater, + pub(crate) updater: Updater, /// The desktop app turns the check at start on; tests and the web build leave it off. #[cfg(not(target_arch = "wasm32"))] startup_check: bool, @@ -44,6 +44,26 @@ impl EffectcraftApp { } } +/// Restart to Update. With unsaved changes the result dialog closes and the window is asked to +/// close, so the unsaved-changes prompt opens. Cancel there leaves the update ready. An open +/// startup prompt keeps its own Restart to Update and save-first note, so the window stays open. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn restart_to_update(rt: &mut Runtime, ctx: &egui::Context, clean: bool) { + if clean { + rt.updater.restart_to_update(); + return; + } + rt.manual_window_open = false; + rt.updater.dismiss_status(); + if rt.updater.prompt_open() { + return; + } + // Without a prompt this only takes the close a finished installation queued, so a save after + // Cancel does not close the app. + let _ = rt.updater.show_if(ctx, true); + ctx.send_viewport_cmd(egui::ViewportCommand::Close); +} + pub(crate) fn check(app: &mut EffectcraftApp) { #[cfg(not(target_arch = "wasm32"))] { @@ -91,7 +111,7 @@ pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) { rt.updater.dismiss_status(); } CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), - CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), + CheckResultResponse::RestartToUpdate => restart_to_update(rt, ctx, clean), } // A check that found a release leaves the status idle and the startup prompt takes over. if matches!(rt.updater.status(), Status::Idle) && !rt.check_requested { From 131e4b325258021a6b7902641797c353497fdb94 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 14:43:58 -0800 Subject: [PATCH 14/24] Fonts: substitute test checks whether the original family is installed microsoft_families_resolve_to_metric_compatible_substitutes took resolve's own answer as the sign that Calibri or Cambria is installed, so it passed when an installed original lost to its substitute. It now looks for the family among the registered faces and, when it is there, requires resolve to pick it and report it as not missing. --- crates/text/src/fonts/tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/text/src/fonts/tests.rs b/crates/text/src/fonts/tests.rs index 2e04e5f0e..d0cb53ea5 100644 --- a/crates/text/src/fonts/tests.rs +++ b/crates/text/src/fonts/tests.rs @@ -459,7 +459,9 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { let resolved = resolve(requested, style); let family = &face(resolved.face).info.family; - if family.eq_ignore_ascii_case(requested) { + let installed = all_faces().iter().any(|f| f.info.family.eq_ignore_ascii_case(requested)); + if installed { + assert!(family.eq_ignore_ascii_case(requested), "an installed {requested} wins over {family}"); assert!(!resolved.missing, "an installed original family is available"); } else { assert_eq!(family, substitute); From c48abd7964982e916e3ae007f6a2dbc31ced9f9d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 11 Nov 2026 15:07:52 -0800 Subject: [PATCH 15/24] Fonts: test that an installed Microsoft family wins over its substitute --- crates/text/src/fonts/tests.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/text/src/fonts/tests.rs b/crates/text/src/fonts/tests.rs index d0cb53ea5..ba1e33b25 100644 --- a/crates/text/src/fonts/tests.rs +++ b/crates/text/src/fonts/tests.rs @@ -473,6 +473,24 @@ fn microsoft_families_resolve_to_metric_compatible_substitutes() { assert!(unknown.missing); } +/// An installed Microsoft family is used as is and not reported missing, even when its +/// substitute is also available (#1677). It runs in a child process so the Calibri fixture does +/// not reach the substitute test above. +#[test] +#[cfg(not(target_arch = "wasm32"))] +fn an_installed_microsoft_family_wins_over_its_substitute() { + const CHILD: &str = "EFFECTCRAFT_TEST_ISOLATED_CALIBRI"; + if std::env::var_os(CHILD).is_none() { + run_in_child(CHILD, "fonts::tests::an_installed_microsoft_family_wins_over_its_substitute"); + return; + } + add_font_data(test_font("Carlito")); + add_font_data(test_font("Calibri")); + let resolved = resolve("Calibri", "Regular"); + assert_eq!(face(resolved.face).info.family, "Calibri"); + assert!(!resolved.missing, "the installed family is available"); +} + #[test] fn the_han_order_follows_the_cjk_locale() { // Chinese first for any Chinese tag, whether or not it names a script. From 02e304a19b0d93762ca94ca17311b5a65276fe25 Mon Sep 17 00:00:00 2001 From: Zinadin Zidan Date: Sat, 14 Nov 2026 22:18:48 +0600 Subject: [PATCH 16/24] Angles: typing into a negative angle's degrees replaces its minus sign (#3367) The degrees field of an angle (Rotation, an effect's angle) showed the remainder's size, with the minus sign painted beside it, and a typed number was taken as a size that kept the sign: 50 typed into 0x-20.0 gave -50. The minus sign is now part of the degrees' text, so it is selected with the rest when typing starts, and a typed number is the new remainder with its sign: 50 gives +50, -50 gives -50. A positive remainder still shows its + beside the field. Fixes #3367 --- crates/ui-egui/src/panels/fx_widgets.rs | 26 +++++++++++++------------ crates/ui-egui/tests/it/ui_angles.rs | 22 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/panels/fx_widgets.rs b/crates/ui-egui/src/panels/fx_widgets.rs index b3140d394..f9ef8e6b2 100644 --- a/crates/ui-egui/src/panels/fx_widgets.rs +++ b/crates/ui-egui/src/panels/fx_widgets.rs @@ -41,15 +41,15 @@ pub fn parse_angle(s: &str) -> Option { s.parse().ok() } -/// The angle after the degrees field of `v` (which shows `shown`, the remainder's size) went to +/// The angle after the degrees field of `v` (which shows `shown`, the signed remainder) went to /// `new`. A drag moves the angle by the pointer's distance, so it runs through zero into negative -/// angles; a typed number is a size, so the remainder keeps its sign. +/// angles; a typed number is the new remainder, its sign included (#3367). fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 { if dragging { return v + (new - shown); } - let (rev, deg) = split_angle(v); - rev as f64 * 360.0 + if deg < 0.0 || (deg == 0.0 && v < 0.0) { -new } else { new } + let (rev, _) = split_angle(v); + rev as f64 * 360.0 + new } /// An angle value, `0x+45.0°`, at `at` (top left): the revolutions and the degrees @@ -58,13 +58,14 @@ fn degrees_edit(v: f64, shown: f64, new: f64, dragging: bool) -> f64 { pub fn angle_field(ui: &mut egui::Ui, at: Pos2, id: egui::Id, v: f64, decimals: usize, t: &Tokens) -> (Rect, Rect, Option) { let (rev, deg) = split_angle(v); let (rr, new_rev, _) = widgets::hot_int_at(ui, at, id.with("rev"), rev, 0.1, "x", t); - let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "-" } else { "+" }, Tokens::ui(12.0), t.hot_text); + // A negative remainder's minus sign is part of the degrees' text, so typing replaces it (#3367). + let sign = ui.painter().text(pos2(rr.max.x - 2.0, rr.center().y), Align2::LEFT_CENTER, if deg < 0.0 { "" } else { "+" }, Tokens::ui(12.0), t.hot_text); let (dr, new_deg, _) = - widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg.abs(), &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t); + widgets::hot_number_at(ui, pos2(sign.max.x - 2.0, at.y), id, deg, &widgets::HotSpec { speed: 0.5, range: (-1e9, 1e9), decimals, suffix: "°" }, t); let dragging = new_deg.is_some() && ui.ctx().is_being_dragged(id); let out = match (new_rev, new_deg) { (Some(r), _) => Some(r as f64 * 360.0 + deg), - (None, Some(d)) => Some(degrees_edit(v, deg.abs(), d, dragging)), + (None, Some(d)) => Some(degrees_edit(v, deg, d, dragging)), (None, None) => None, }; (rr, dr, out) @@ -624,18 +625,19 @@ mod tests { #[test] fn dragging_degrees_crosses_zero_into_negative_angles() { - // The field shows the size (0.3), so a 1-degree drag left lands on -0.7, and keeps going. + // A 1-degree drag left from 0.3 lands on -0.7, and keeps going. let mut v = 0.3; for _ in 0..3 { let (_, deg) = split_angle(v); - v = degrees_edit(v, deg.abs(), deg.abs() - 1.0, true); + v = degrees_edit(v, deg, deg - 1.0, true); } assert!((v + 2.7).abs() < 1e-9, "{v}"); // And back up through zero. let (_, deg) = split_angle(v); - assert!((degrees_edit(v, deg.abs(), deg.abs() + 3.0, true) - 0.3).abs() < 1e-9); - // Typing keeps the sign shown. - assert_eq!(degrees_edit(-30.0, 30.0, 45.0, false), -45.0); + assert!((degrees_edit(v, deg, deg + 3.0, true) - 0.3).abs() < 1e-9); + // A typed number is the remainder with its sign; the revolutions stay (#3367). + assert_eq!(degrees_edit(-30.0, -30.0, 45.0, false), 45.0); + assert_eq!(degrees_edit(-30.0, -30.0, -45.0, false), -45.0); assert_eq!(degrees_edit(405.0, 45.0, 10.0, false), 370.0); } diff --git a/crates/ui-egui/tests/it/ui_angles.rs b/crates/ui-egui/tests/it/ui_angles.rs index 40ad17bc1..c98dfa9ff 100644 --- a/crates/ui-egui/tests/it/ui_angles.rs +++ b/crates/ui-egui/tests/it/ui_angles.rs @@ -191,3 +191,25 @@ fn commit_edits(click_away: bool) { } } } + +/// #3367: on a negative angle the minus sign is part of the degrees typing replaces, so typing +/// 50 into `0x-20.0°` sets +50°. It used to keep the sign (-50°). Committing the text as it +/// opened keeps the angle. +#[test] +fn typing_into_a_negative_angle_replaces_its_sign() { + for panel in [Panel::EffectControls, Panel::Timeline, Panel::Properties] { + for (start, text, expected) in + [(-20.0, Some("50"), 50.0), (-20.0, Some("-50"), -50.0), (-20.0, None, -20.0), (-400.0, None, -400.0), (45.0, Some("-30"), -30.0)] + { + let (mut h, layer, uid) = harness(panel, start); + let p = component(&h, panel, uid, false); + click(&mut h, p); + if let Some(text) = text { + h.input_mut().events.push(Event::Text(text.into())); + h.step(); + } + key(&mut h, Key::Enter, Modifiers::NONE); + assert_eq!(angle(&h, layer, uid), expected, "{panel:?}: {start} then {text:?}"); + } + } +} From 3bc37b0b8b22d1c1b5bcc45f3f71c118eb3111e7 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 19:18:24 +0100 Subject: [PATCH 17/24] Drop the duplicate expression_toggled that the merge brought in from main --- crates/ui-egui/src/panels/timeline.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index af7254e5e..dd92ef941 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -4298,19 +4298,6 @@ fn prop_context_menu( } } -/// An expression was just added to `prop` (it had none) or removed: adding one opens its -/// editor, which comes into view and takes the keyboard with the new expression selected -/// (#1072); removing it leaves nothing to take the keyboard. -fn expression_toggled(app: &mut EffectcraftApp, ctx: &egui::Context, prop: &Property) { - let uid = prop.uid; - if prop.expr.is_none() { - app.ui.timeline.expr_closed.remove(&uid); - focus_expression(ctx, uid, [usize::MAX, 0]); - } else if ctx.data(|d| d.get_temp::(expr_focus_id())).is_some_and(|f| f.prop == uid) { - ctx.data_mut(|d| d.remove::(expr_focus_id())); - } -} - /// The value editors and the property pick whip. fn prop_value_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ectx: &EvalCtx<'_>, prop: &Property, name_x: f32) { let vis = g.tl.vis; From c1f3a03a9d0aa0591cd52979c29b8ff65235719e Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 18/24] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From 2780a503029349a721d85acf0decea93f20a4d21 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 19/24] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From 0a3d74fb5474e599e63908914d39fcd0e22c8e61 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sat, 14 Nov 2026 18:50:35 +0100 Subject: [PATCH 20/24] ui-egui tests: the file.import dialog answers carry paths as Ok, as DialogAnswer.paths is a Result now (#3304 met the tests of #3103 on main) --- crates/ui-egui/src/menus/tests.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/menus/tests.rs b/crates/ui-egui/src/menus/tests.rs index 0acab9ef9..8c5091691 100644 --- a/crates/ui-egui/src/menus/tests.rs +++ b/crates/ui-egui/src/menus/tests.rs @@ -823,7 +823,7 @@ fn import_file_dialog_offers_and_imports_after_effects_projects() { assert!(many && exts.iter().any(|e| e == "aep") && exts.iter().any(|e| e == "aepx"), "{exts:?}"); assert!(exts.iter().any(|e| e == "png"), "footage too"); - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: vec![aep] }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(vec![aep]) }); let comp = app.session.project.item(app.session.active_comp_id().expect("a composition is open")).unwrap(); assert_eq!(comp.name, "Intro"); assert_eq!(app.session.project.item(comp.parent.expect("in a folder")).unwrap().name, "Intro.aep"); @@ -884,7 +884,10 @@ fn picked_projects_report_every_error() { std::fs::write(&aep, b"not an aep").unwrap(); std::fs::write(&ecproj, b"not a project").unwrap(); let paths = vec![aep.to_string_lossy().to_string(), ecproj.to_string_lossy().to_string()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: paths.clone() }); + super::frontend::dialog_answered( + &mut app, + crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths.clone()) }, + ); let status = &app.ui.status; assert!(status.contains("broken.aep") && status.contains("broken.ecproj"), "{status}"); assert!(!status.contains('"'), "messages, not quoted JSON: {status}"); @@ -915,7 +918,7 @@ fn a_picked_project_with_losses_asks_and_the_next_waits() { source.execute("comp.new", json!({"name": "Intro", "width": 64, "height": 36, "frameRate": 30, "duration": 1})).unwrap(); source.execute("file.exportAep", json!({"path": intro, "allowLosses": true})).unwrap(); let paths = vec![lossy.to_string_lossy().to_string(), intro.clone()]; - super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths }); + super::frontend::dialog_answered(&mut app, crate::DialogAnswer { command: "file.import".into(), key: "paths", params: json!({}), paths: Ok(paths) }); assert_eq!(app.dialog, Some(crate::Dialog::AepLosses)); assert_eq!(app.dialog_state.aep_losses.queue, [intro]); assert!(app.session.project.items.is_empty(), "nothing imported before the answer"); From 3a2a564b4bba88c85b5c0ddf5bf1b9936f98ac58 Mon Sep 17 00:00:00 2001 From: Madhav Agarwal Date: Sun, 15 Nov 2026 09:08:04 +0530 Subject: [PATCH 21/24] docs: bring ROADMAP.md current through 2026-11-15 --- ROADMAP.md | 1 + docs/target-app-parity.md | 1 + 2 files changed, 2 insertions(+) diff --git a/ROADMAP.md b/ROADMAP.md index 656487144..88fa7335e 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,6 +2,7 @@ **Stage: alpha** · next: beta, ~30 points of "ready for real work" and ~350–620 h away +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (releases v0.22.0 through v0.24.1; .aep gained project export (#2594), drag-and-drop import (#3103), an audit of hostile inputs with every loss reported (#3299, #3300, #3319, #3365), placeholders for unmapped effects (#3087), Lumetri Color, Puppet, CC Color Neutralizer, EXtractoR/IDentifier, HDR Highlight Compression, Echo, Linear Wipe, Offset and Color Stabilizer mappings, text-animator and Source Text expressions (#3170) and twice the import speed (#3302); GPU rendering 2.6× faster with one upload per frame and single-copy readback (#3335), smooth preview lanes (#3345), bounded GPU memory (#3028), shared multi-layer EXR decode (#474), EXR output options (#2915, #2916) and a WebAssembly ABI 2 plug-in path (#3329); eighteen effect parameters now take After Effects' ranges (#3470–#3480, #3483–#3484, #3487–#3491), with Color Stabilizer sampling (#3125), masked Grid/Checkerboard/Circle (#3121), Cryptomatte selection and Matte Only (#2839, #3130), fast-conformed frame blending (#3180) and bounded Levels and time-stretch math; number-field arithmetic (#3195), expressionError (#3219), prop.get with footage (#3231), reversed-layer audio (#3239), keyframed audio waveforms (#1722), Effect Controls lock and rename selection (#3193, #3198), viewer snapping (#2681, #3229), Graph Editor theming (#3202), Convert To Bezier Path (#3237), stopwatch Add Expression (#3192), Shift-drag timeline snapping (#1828), anchored marquee (#2859), Go to Time (#3373), text layers whose names follow their text (#3233), mute-aware audio preview (#2104), ScriptUI panel bars (#2796), Closed-path and Effect Controls arrow fixes (#2817, #2869) and accessible Info, Flowchart, Script Console and 3D Camera Tracker blocks (#1341); a file-dialog crash fix (#3084), crash diagnostics and replayable repros (#3357, #1224), Flatpak updater and nightly release fixes (#3516, #3520), craft-libs format and update cutovers, and CI test stabilisation (#3650, #3689, #3704); readiness estimates unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-22 · **Last updated:** 2026-11-05 · **Change:** minor (ProRes alpha final-run conformance; previously: features of 30 October in the progress log: text Line Join, Timeline drag-reorder and multi-select of effects, viewer edge pan, ScriptUI drag capture and dock size; previously: localization recount after #1774) · **Target:** Adobe After Effects 2026 (26.5.0.89) EffectCraft aims to do what After Effects does, with the same panels, menus and behaviour, written diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 247887345..09f9df6bc 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1,5 +1,6 @@ # Parity with After Effects +> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (ROADMAP sync over 5–15 November: .aep export, drag-and-drop import, hostile-input audit and loss reporting, effect placeholders and mappings, 2.6× GPU rendering, EXR output options, eighteen aligned effect ranges and a broad editor/expression fix batch; releases v0.22.0–v0.24.1. No parity numbers re-measured; the 10 October re-measure and all readiness estimates are unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) > **Last reviewed:** 2026-10-12 · **Last updated:** 2026-10-12 · **Change:** minor (issue, catalog and export-format references re-audited against `upstream/main` 470ea7a3; the 10 October re-measure is otherwise unchanged) · **Target:** Adobe After Effects 2026 (26.5.0.89) The authoritative assessment of how close EffectCraft is to After Effects, and how much work is From 186661829a677a7555e72f26b212d771eb2e81a6 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 08:18:00 +0100 Subject: [PATCH 22/24] media: decode animated GIF and WebP through craft-gif and craft-webp frames Carved out of #3649. craft_gif::frames and craft_webp::frames replace the image crate's animation decoders in gif_anim and webp_anim, with the same frame, byte and canvas limits and the same damaged-tail behaviour (frames decoded before the damage are kept). craft-gif and craft-webp are pinned to craft-libs main 948b5c23 with the frames feature. --- Cargo.lock | 9 ++- Cargo.toml | 4 +- crates/media/Cargo.toml | 4 +- crates/media/src/gif_anim.rs | 147 ++++++++++++++++++++++++++-------- crates/media/src/webp_anim.rs | 119 +++++++++++++++++++++------ 5 files changed, 219 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f68689a2..b95410306 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1166,7 +1166,11 @@ source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b4255 [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" +dependencies = [ + "gif", + "image", +] [[package]] name = "craft-i18n" @@ -1361,8 +1365,9 @@ dependencies = [ [[package]] name = "craft-webp" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=47107f660191de2f0b425569506f4daa4faadac9#47107f660191de2f0b425569506f4daa4faadac9" +source = "git+https://github.com/storytold/craft-libs?rev=948b5c23c12dc8c87c8b1828892b1462113dd5a7#948b5c23c12dc8c87c8b1828892b1462113dd5a7" dependencies = [ + "image", "thiserror 2.0.21", ] diff --git a/Cargo.toml b/Cargo.toml index 13e062ee6..eb297bd7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,10 +19,10 @@ craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/c craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-eps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } -craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } +craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "948b5c23c12dc8c87c8b1828892b1462113dd5a7" } craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2284a6bf76b3d629b5e5bb2ca71e1c319d8dae5f" } craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9", default-features = false, features = ["stl", "obj", "gltf", "fbx"] } craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "47107f660191de2f0b425569506f4daa4faadac9" } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index f744c684c..2922a1a7c 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -24,8 +24,8 @@ filmcraft-codecs = { workspace = true } filmcraft-media = { workspace = true } craft-dpx = { workspace = true } craft-exr = { workspace = true } -craft-gif = { workspace = true } -craft-webp = { workspace = true } +craft-gif = { workspace = true, features = ["frames"] } +craft-webp = { workspace = true, features = ["frames"] } craft-audio = { workspace = true } craft-media = { workspace = true } filmcraft-mpegts = { workspace = true } diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index 8453b50ac..e2cac5aa8 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -5,11 +5,9 @@ //! delays), so uneven timing is kept exactly; [`Anim::frame_at`] looks the frame up by time. //! Animated WebP ([`crate::webp_anim`]) shares [`Anim`] and this decode path. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::gif::GifDecoder}; +use image::DynamicImage; use crate::{MediaError, Result}; @@ -86,39 +84,39 @@ impl Anim { if crate::webp_anim::is_webp(bytes) { return crate::webp_anim::load(bytes); } - let mut dec = GifDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // A frame may be far larger than the canvas, and the decoder allocates its buffer before - // decoding it: no single buffer may pass what all the frames may hold. - let mut limits = image::Limits::no_limits(); - limits.max_alloc = Some(MAX_BYTES as u64); - image::ImageDecoder::set_limits(&mut dec, limits).map_err(|e| MediaError::Decode(format!("GIF: {e}")))?; - // The decoder allocates the full logical canvas for the first frame, however small the - // frames themselves are: check it before decoding any. - let (w, h) = image::ImageDecoder::dimensions(&dec); - if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { - return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); - } - let (mut frames, mut starts) = (Vec::new(), Vec::new()); - let (mut at, mut size) = (0i64, 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("GIF: {e}"))), - Err(e) => { - log::warn!("media: GIF stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - let cs = delay_cs(numer.checked_div(denom).unwrap_or(0) / 10); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + let mut limits = craft_gif::frames::FrameLimits::default(); + limits.max_frames = MAX_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + limits.max_decode_bytes = Some(MAX_BYTES as u64); + let decoded = craft_gif::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_gif::frames::FrameError::Malformed(m) => MediaError::Decode(format!("GIF: {m}")), + craft_gif::frames::FrameError::LimitExceeded(m) + if m.contains("cannot hold") || m.contains("decode-allocation limit") || m.to_ascii_lowercase().contains("memory limit") => + { + MediaError::Unsupported("GIF is too large to hold in memory".into()) } + craft_gif::frames::FrameError::LimitExceeded(m) if m.contains("canvas is over") => { + MediaError::Unsupported("GIF canvas is too large to hold in memory".into()) + } + craft_gif::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("GIF: {m}")), + })?; + if matches!(&decoded.stop, craft_gif::frames::Stop::ByteLimit | craft_gif::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("GIF is too large to hold in memory".into())); + } + if let craft_gif::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: GIF stops after {} frames: {e}", decoded.frames.len()); + } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut starts = Vec::with_capacity(decoded.frames.len()); + let mut at = 0i64; + for frame in decoded.frames { + let cs = delay_cs(frame.delay_ms / 10); + let image = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("GIF: invalid decoded frame dimensions".into()))?; starts.push(Tick::from_units(at, 100)); at = at.saturating_add(i64::from(cs)); - frames.push(DynamicImage::ImageRgba8(buf)); + frames.push(DynamicImage::ImageRgba8(image)); } Anim::new(frames, starts).ok_or_else(|| MediaError::Decode("GIF: no frames".into())) } @@ -133,9 +131,13 @@ impl Anim { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; + use image::AnimationDecoder; + use super::MAX_FRAMES; use crate::{MediaPool, probe_bytes}; /// A 2×2 GIF with one solid-colour frame per `(rgb, delay)`. @@ -152,6 +154,15 @@ mod tests { out } + /// Preserve the old consumer path as a test oracle while the frame API is shared. + fn legacy_gif_frames(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect() + } + + fn legacy_gif_frames_until_error(bytes: &[u8]) -> Vec { + image::codecs::gif::GifDecoder::new(Cursor::new(bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect() + } + const RED: [u8; 3] = [255, 0, 0]; const GREEN: [u8; 3] = [0, 255, 0]; const BLUE: [u8; 3] = [0, 0, 255]; @@ -201,6 +212,62 @@ mod tests { assert_eq!(f.duration, Tick::from_units(20, 100)); } + #[test] + fn shared_gif_frames_match_legacy_compositing_and_disposal() { + let mut bytes = Vec::new(); + { + let palette = [255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0]; + let mut enc = gif::Encoder::new(&mut bytes, 3, 2, &palette).unwrap(); + let first = gif::Frame { + width: 3, + height: 2, + buffer: vec![0; 6].into(), // red background + delay: 5, + dispose: gif::DisposalMethod::Keep, + ..gif::Frame::default() + }; + enc.write_frame(&first).unwrap(); + + let second = gif::Frame { + left: 1, + width: 1, + height: 1, + buffer: vec![1].into(), // green patch + delay: 7, + dispose: gif::DisposalMethod::Background, + ..gif::Frame::default() + }; + enc.write_frame(&second).unwrap(); + + let third = gif::Frame { + left: 2, + width: 1, + height: 1, + buffer: vec![2].into(), // blue patch after disposal + delay: 9, + dispose: gif::DisposalMethod::Previous, + ..gif::Frame::default() + }; + enc.write_frame(&third).unwrap(); + + let fourth = gif::Frame { + width: 1, + height: 1, + buffer: vec![3].into(), // black patch after restoring the previous canvas + delay: 11, + ..gif::Frame::default() + }; + enc.write_frame(&fourth).unwrap(); + } + let expected = legacy_gif_frames(&bytes); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), expected.len()); + for (frame, old) in actual.frames.iter().zip(expected) { + assert_eq!(frame.to_rgba8(), old); + } + assert_eq!(actual.starts, vec![Tick::from_units(0, 100), Tick::from_units(5, 100), Tick::from_units(12, 100), Tick::from_units(21, 100)]); + } + #[test] fn a_single_frame_gif_stays_a_still() { let f = probe_bytes("a.gif", gif(&[(RED, 10)]).into()).unwrap(); @@ -228,6 +295,20 @@ mod tests { let _ = probe_bytes("a.gif", bytes.into()); } + #[test] + fn a_damaged_gif_tail_keeps_frames_already_decoded() { + let mut bytes = gif(&[(RED, 5), (GREEN, 5), (BLUE, 5)]); + let info = craft_gif::scan(&bytes, MAX_FRAMES).unwrap(); + assert_eq!(info.frames.len(), 3); + bytes.truncate(info.frames[1].offset); + + let legacy = legacy_gif_frames_until_error(&bytes); + assert_eq!(legacy.len(), 1); + let actual = super::Anim::load(&bytes).unwrap(); + assert_eq!(actual.frames.len(), legacy.len()); + assert_eq!(actual.frames[0].to_rgba8(), legacy[0]); + } + #[test] fn a_huge_canvas_is_refused_before_decoding() { // A 65535×65535 logical screen (16 GiB of RGBA) holding one 1×1 frame. diff --git a/crates/media/src/webp_anim.rs b/crates/media/src/webp_anim.rs index 147fe8264..dbe664fac 100644 --- a/crates/media/src/webp_anim.rs +++ b/crates/media/src/webp_anim.rs @@ -9,11 +9,9 @@ //! every delay is a whole number of frames at (1000 / the greatest common divisor of the delays), //! so it is kept exactly. A still WebP (no animation flag, or a single frame) stays a still. -use std::io::Cursor; - use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; -use image::{AnimationDecoder, DynamicImage, codecs::webp::WebPDecoder}; +use image::DynamicImage; use crate::gif_anim::{Anim, MAX_BYTES, MAX_FRAMES, gcd}; use crate::{MediaError, Result}; @@ -121,29 +119,29 @@ pub(crate) fn load(bytes: &[u8]) -> Result { if frame_bytes.saturating_mul(h.delays.len()) > MAX_BYTES { return Err(MediaError::Unsupported(format!("animated WebP of {} frames of {}×{} is too large to hold in memory", h.delays.len(), h.width, h.height))); } - let dec = WebPDecoder::new(Cursor::new(bytes)).map_err(|e| MediaError::Decode(format!("WebP: {e}")))?; - // The budget above used the canvas this file's header scan found; the decoder must agree, or - // a second VP8X header could make it allocate a far larger canvas. - if image::ImageDecoder::dimensions(&dec) != (h.width, h.height) { + let mut limits = craft_webp::frames::FrameLimits::default(); + limits.max_frames = MAX_FRAMES; + limits.max_bytes = MAX_BYTES as u64; + limits.max_canvas_bytes = MAX_BYTES as u64; + let decoded = craft_webp::frames::read_frames(bytes, &limits).map_err(|e| match e { + craft_webp::frames::FrameError::Malformed(m) => MediaError::Decode(format!("WebP: {m}")), + craft_webp::frames::FrameError::LimitExceeded(m) => MediaError::Unsupported(format!("WebP: {m}")), + })?; + if matches!(&decoded.stop, craft_webp::frames::Stop::ByteLimit | craft_webp::frames::Stop::FrameLimit) { + return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); + } + if let craft_webp::frames::Stop::Damaged(ref e) = decoded.stop { + log::warn!("media: WebP stops after {} frames: {e}", decoded.frames.len()); + } + if (decoded.width, decoded.height) != (h.width, h.height) { return Err(MediaError::Decode("WebP: conflicting canvas sizes".into())); } - let (mut frames, mut delays, mut size) = (Vec::new(), Vec::new(), 0usize); - for frame in dec.into_frames() { - let frame = match frame { - Ok(f) => f, - Err(e) if frames.is_empty() => return Err(MediaError::Decode(format!("WebP: {e}"))), - Err(e) => { - log::warn!("media: WebP stops after {} frames: {e}", frames.len()); - break; - } - }; - let (numer, denom) = frame.delay().numer_denom_ms(); - delays.push(numer.checked_div(denom).unwrap_or(0)); - let buf = frame.into_buffer(); - size = size.saturating_add(buf.as_raw().len()); - if size > MAX_BYTES { - return Err(MediaError::Unsupported("animated WebP is too large to hold in memory".into())); - } + let mut frames = Vec::with_capacity(decoded.frames.len()); + let mut delays = Vec::with_capacity(decoded.frames.len()); + for frame in decoded.frames { + delays.push(frame.delay_ms); + let buf = image::RgbaImage::from_raw(decoded.width, decoded.height, frame.rgba) + .ok_or_else(|| MediaError::Decode("WebP: invalid decoded frame dimensions".into()))?; frames.push(DynamicImage::ImageRgba8(buf)); } let starts = timing(&delays).starts; @@ -152,9 +150,11 @@ pub(crate) fn load(bytes: &[u8]) -> Result { #[cfg(test)] mod tests { + use std::io::Cursor; + use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; - use image::{ExtendedColorType, ImageEncoder, codecs::webp::WebPEncoder}; + use image::{AnimationDecoder, ExtendedColorType, ImageEncoder, codecs::webp::WebPDecoder, codecs::webp::WebPEncoder}; use super::timing; use crate::{MediaPool, probe_bytes}; @@ -204,6 +204,43 @@ mod tests { chunk(b"RIFF", &body) } + /// Build an animation whose frames may cover only part of the canvas. `x` and `y` are even, + /// as required by ANMF; bit 1 of `flags` selects no-blend and bit 0 selects disposal. + fn webp_subframes(canvas: (u32, u32), frames: &[(u32, u32, u32, u32, [u8; 4], u32, u8)]) -> Vec { + let (w, h) = canvas; + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(w - 1)); + vp8x.extend_from_slice(&u24(h - 1)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for &(x, y, fw, fh, rgba, delay, flags) in frames { + let mut anmf = Vec::new(); + anmf.extend_from_slice(&u24(x / 2)); + anmf.extend_from_slice(&u24(y / 2)); + anmf.extend_from_slice(&u24(fw - 1)); + anmf.extend_from_slice(&u24(fh - 1)); + anmf.extend_from_slice(&u24(delay)); + anmf.push(flags); + anmf.extend(vp8l(fw, fh, rgba)); + body.extend(chunk(b"ANMF", &anmf)); + } + chunk(b"RIFF", &body) + } + + fn anmf_offsets(bytes: &[u8]) -> Vec { + let mut offsets = Vec::new(); + let mut at = 12usize; + while at + 8 <= bytes.len() { + let size = u32::from_le_bytes(bytes[at + 4..at + 8].try_into().unwrap()) as usize; + if &bytes[at..at + 4] == b"ANMF" { + offsets.push(at); + } + at = at.saturating_add(8).saturating_add(size).saturating_add(size & 1); + } + offsets + } + const RED: [u8; 4] = [255, 0, 0, 255]; const GREEN: [u8; 4] = [0, 255, 0, 255]; const BLUE: [u8; 4] = [0, 0, 255, 128]; @@ -238,6 +275,38 @@ mod tests { assert_eq!(pixel_at(&pool, &f, 5.0), last); } + #[test] + fn shared_webp_frames_match_legacy_subrect_blending_and_disposal() { + // Includes a blended alpha patch, then a no-blend patch disposed to the background. + let bytes = + webp_subframes((4, 2), &[(0, 0, 4, 2, RED, 50, 0b10), (2, 0, 2, 2, BLUE, 60, 0b00), (0, 0, 2, 2, GREEN, 70, 0b11), (2, 0, 2, 2, RED, 80, 0b10)]); + let expected = WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map(|frame| frame.unwrap().into_buffer()).collect::>(); + let actual = super::load(&bytes).unwrap(); + assert_eq!(expected.len(), 4); + for (index, (start_ms, old)) in [(0, &expected[0]), (50, &expected[1]), (110, &expected[2]), (180, &expected[3])].into_iter().enumerate() { + let tick = Tick::from_units(start_ms, 1000); + let frame = actual.frame_at(tick).unwrap().to_rgba8(); + assert_eq!(frame, *old, "frame {index} at {start_ms} ms"); + } + } + + #[test] + fn a_damaged_webp_tail_keeps_frames_already_decoded() { + let mut bytes = webp(4, 2, &[(RED, 50), (GREEN, 60), (BLUE, 70)]); + let offsets = anmf_offsets(&bytes); + assert_eq!(offsets.len(), 3); + bytes.truncate(offsets[2]); + + let legacy = + WebPDecoder::new(Cursor::new(&bytes)).unwrap().into_frames().map_while(|frame| frame.ok()).map(|frame| frame.into_buffer()).collect::>(); + assert_eq!(legacy.len(), 2); + let actual = super::load(&bytes).unwrap(); + for (index, old) in legacy.iter().enumerate() { + let tick = Tick::from_units(if index == 0 { 0 } else { 50 }, 1000); + assert_eq!(actual.frame_at(tick).unwrap().to_rgba8(), *old); + } + } + #[test] fn delays_rounded_to_milliseconds_read_as_the_standard_rate() { // 24 frames a second rounded to whole milliseconds, as ffmpeg writes them. From 9e27d5a0a5e6a87b3a7fef3f1665e21f4268ab17 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:14:28 +0100 Subject: [PATCH 23/24] fix(media): keep every decoded GIF and WebP frame past the probe frame count --- crates/media/src/gif_anim.rs | 34 +++++++++++++++++++++++++++++++++- crates/media/src/webp_anim.rs | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index e2cac5aa8..117f85d9b 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -24,6 +24,10 @@ pub(crate) const MAX_BYTES: usize = 256 << 20; /// Frames read from a GIF's or animated WebP's headers when probing. pub(crate) const MAX_FRAMES: usize = 100_000; +/// Frames kept when decoding a GIF or animated WebP: all of them. Only [`MAX_BYTES`] and the +/// canvas budget bound decoding, as before the shared frame readers; [`MAX_FRAMES`] bounds probing. +pub(crate) const DECODE_FRAMES: usize = usize::MAX; + /// Whether `f` is an animated GIF or WebP imported by [`probe`] or [`crate::webp_anim::probe`]: /// its frames come from an [`Anim`]. pub(crate) fn is_animated(f: &Footage) -> bool { @@ -85,7 +89,7 @@ impl Anim { return crate::webp_anim::load(bytes); } let mut limits = craft_gif::frames::FrameLimits::default(); - limits.max_frames = MAX_FRAMES; + limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; limits.max_canvas_bytes = MAX_BYTES as u64; limits.max_decode_bytes = Some(MAX_BYTES as u64); @@ -121,6 +125,12 @@ impl Anim { Anim::new(frames, starts).ok_or_else(|| MediaError::Decode("GIF: no frames".into())) } + /// How many frames were decoded. + #[cfg(test)] + pub(crate) fn len(&self) -> usize { + self.frames.len() + } + /// The frame shown at source time `t` (the first one before the start, the last one past the /// end). pub(crate) fn frame_at(&self, t: Tick) -> Option<&DynamicImage> { @@ -322,4 +332,26 @@ mod tests { let e = super::Anim::load(&out).err().unwrap(); assert!(e.to_string().contains("too large"), "{e}"); } + + /// A 1×1 GIF of `n` frames. + fn tiny_gif(n: usize) -> Vec { + let mut out = Vec::new(); + { + let mut enc = gif::Encoder::new(&mut out, 1, 1, &[]).unwrap(); + let frame = gif::Frame::from_rgb(1, 1, &RED); + for _ in 0..n { + enc.write_frame(&frame).unwrap(); + } + } + out + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [MAX_FRAMES, MAX_FRAMES + 1] { + let anim = super::Anim::load(&tiny_gif(n)).unwrap(); + assert_eq!(anim.len(), n); + } + } } diff --git a/crates/media/src/webp_anim.rs b/crates/media/src/webp_anim.rs index dbe664fac..bb2fdcc69 100644 --- a/crates/media/src/webp_anim.rs +++ b/crates/media/src/webp_anim.rs @@ -13,7 +13,7 @@ use effectcraft_project::{AlphaMode, Footage, FootageKind}; use effectcraft_time::{FrameRate, Tick}; use image::DynamicImage; -use crate::gif_anim::{Anim, MAX_BYTES, MAX_FRAMES, gcd}; +use crate::gif_anim::{Anim, DECODE_FRAMES, MAX_BYTES, MAX_FRAMES, gcd}; use crate::{MediaError, Result}; /// The `Footage::codec` of an animated WebP. @@ -120,7 +120,7 @@ pub(crate) fn load(bytes: &[u8]) -> Result { return Err(MediaError::Unsupported(format!("animated WebP of {} frames of {}×{} is too large to hold in memory", h.delays.len(), h.width, h.height))); } let mut limits = craft_webp::frames::FrameLimits::default(); - limits.max_frames = MAX_FRAMES; + limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; limits.max_canvas_bytes = MAX_BYTES as u64; let decoded = craft_webp::frames::read_frames(bytes, &limits).map_err(|e| match e { @@ -381,4 +381,34 @@ mod tests { bytes[4..8].copy_from_slice(&riff.to_le_bytes()); assert!(super::load(&bytes).is_err()); } + + /// A 1×1 animated WebP of `n` identical frames. + fn tiny_webp(n: usize) -> Vec { + let mut anmf = vec![0; 6]; + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(0)); + anmf.extend_from_slice(&u24(50)); + anmf.push(0b10); + anmf.extend(vp8l(1, 1, RED)); + let frame = chunk(b"ANMF", &anmf); + let mut vp8x = vec![0x12, 0, 0, 0]; + vp8x.extend_from_slice(&u24(0)); + vp8x.extend_from_slice(&u24(0)); + let mut body = b"WEBP".to_vec(); + body.extend(chunk(b"VP8X", &vp8x)); + body.extend(chunk(b"ANIM", &[0; 6])); + for _ in 0..n { + body.extend_from_slice(&frame); + } + chunk(b"RIFF", &body) + } + + #[test] + fn decoding_keeps_every_frame_past_the_probe_frame_count() { + // 1×1 frames fit the byte budget however many there are: the frame count refuses none. + for n in [crate::gif_anim::MAX_FRAMES, crate::gif_anim::MAX_FRAMES + 1] { + let anim = super::load(&tiny_webp(n)).unwrap(); + assert_eq!(anim.len(), n); + } + } } From da6e5b874c231f74e458378ebbb8cf802dee8b1f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:45:16 +0100 Subject: [PATCH 24/24] fix(media): refuse an oversized GIF canvas before scanning its frames --- crates/media/src/gif_anim.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/media/src/gif_anim.rs b/crates/media/src/gif_anim.rs index 117f85d9b..dc5f55e27 100644 --- a/crates/media/src/gif_anim.rs +++ b/crates/media/src/gif_anim.rs @@ -88,6 +88,14 @@ impl Anim { if crate::webp_anim::is_webp(bytes) { return crate::webp_anim::load(bytes); } + // The frame reader scans every image descriptor before it checks the canvas: refuse a + // logical screen too large to hold first, as the former decoder did. + if let Some(&[w0, w1, h0, h1]) = bytes.get(6..10).filter(|_| bytes.starts_with(b"GIF8")) { + let (w, h) = (u16::from_le_bytes([w0, w1]), u16::from_le_bytes([h0, h1])); + if u64::from(w) * u64::from(h) * 4 > MAX_BYTES as u64 { + return Err(MediaError::Unsupported(format!("GIF canvas of {w}×{h} is too large to hold in memory"))); + } + } let mut limits = craft_gif::frames::FrameLimits::default(); limits.max_frames = DECODE_FRAMES; limits.max_bytes = MAX_BYTES as u64; @@ -330,7 +338,7 @@ mod tests { } } let e = super::Anim::load(&out).err().unwrap(); - assert!(e.to_string().contains("too large"), "{e}"); + assert!(e.to_string().contains("GIF canvas of 65535×65535 is too large"), "{e}"); } /// A 1×1 GIF of `n` frames.