Read vector preview frame through shared SVG preflight

This commit is contained in:
Dylan M. Taylor committed 2026-11-13 06:10:16 -05:00
1 parent 65cb44797d
commit 540879e2eb
3 files changed
+64 -69

No files matched your search

Generated
+33 -33
View File
@@ -1320,7 +1320,7 @@ dependencies = [
[[package]]
name = "craft-affinity"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"crc32fast",
"flate2",
@@ -1331,7 +1331,7 @@ dependencies = [
[[package]]
name = "craft-atomic"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"rustix 1.1.5",
]
@@ -1339,7 +1339,7 @@ dependencies = [
[[package]]
name = "craft-crw"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"thiserror 2.0.21",
]
@@ -1347,17 +1347,17 @@ dependencies = [
[[package]]
name = "craft-docpath"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
[[package]]
name = "craft-eps"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
[[package]]
name = "craft-file-formats"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-eps",
"craft-idml",
@@ -1375,12 +1375,12 @@ dependencies = [
[[package]]
name = "craft-fonts-build"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
[[package]]
name = "craft-heif"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"heic-rs",
"rayon",
@@ -1389,7 +1389,7 @@ dependencies = [
[[package]]
name = "craft-i18n"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"fixed_decimal",
"icu_decimal",
@@ -1412,7 +1412,7 @@ dependencies = [
[[package]]
name = "craft-idml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1422,7 +1422,7 @@ dependencies = [
[[package]]
name = "craft-image-codecs"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-heif",
"craft-jpeg",
@@ -1445,7 +1445,7 @@ dependencies = [
[[package]]
name = "craft-jpeg"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"thiserror 2.0.21",
]
@@ -1453,7 +1453,7 @@ dependencies = [
[[package]]
name = "craft-kra"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1463,7 +1463,7 @@ dependencies = [
[[package]]
name = "craft-metadata"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"brotli-decompressor 6.3.1",
"chrono",
@@ -1475,7 +1475,7 @@ dependencies = [
[[package]]
name = "craft-ora"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-xml",
"craft-zip",
@@ -1485,7 +1485,7 @@ dependencies = [
[[package]]
name = "craft-pcraft-bundle"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"blake3",
"craft-atomic",
@@ -1498,7 +1498,7 @@ dependencies = [
[[package]]
name = "craft-pcraft-format"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"serde",
"serde_json",
@@ -1508,7 +1508,7 @@ dependencies = [
[[package]]
name = "craft-pdf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"bytemuck",
"hayro",
@@ -1520,7 +1520,7 @@ dependencies = [
[[package]]
name = "craft-pdn"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1529,7 +1529,7 @@ dependencies = [
[[package]]
name = "craft-print"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-winprint-gdi",
"log",
@@ -1543,7 +1543,7 @@ dependencies = [
[[package]]
name = "craft-psd"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"encoding_rs",
"flate2",
@@ -1554,7 +1554,7 @@ dependencies = [
[[package]]
name = "craft-raw"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"chrono",
"craft-crw",
@@ -1572,7 +1572,7 @@ dependencies = [
[[package]]
name = "craft-svg"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-image-codecs",
"craft-xml",
@@ -1587,7 +1587,7 @@ dependencies = [
[[package]]
name = "craft-tiff"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"serde",
"thiserror 2.0.21",
@@ -1596,7 +1596,7 @@ dependencies = [
[[package]]
name = "craft-ui"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"craft-fonts-build",
"craft-i18n",
@@ -1617,7 +1617,7 @@ dependencies = [
[[package]]
name = "craft-update"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"chrono",
"dunce",
@@ -1652,7 +1652,7 @@ dependencies = [
[[package]]
name = "craft-xcf"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -1661,7 +1661,7 @@ dependencies = [
[[package]]
name = "craft-xml"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"quick-xml 0.41.0",
"thiserror 2.0.21",
@@ -1670,7 +1670,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"flate2",
"thiserror 2.0.21",
@@ -3076,7 +3076,7 @@ dependencies = [
[[package]]
name = "hayro"
version = "0.7.1"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"bytemuck",
"hayro-interpret",
@@ -3106,7 +3106,7 @@ dependencies = [
[[package]]
name = "hayro-interpret"
version = "0.7.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"bitflags 2.13.2",
"hayro-cmap",
@@ -3124,7 +3124,7 @@ dependencies = [
[[package]]
name = "hayro-jbig2"
version = "0.3.0"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"fearless_simd",
"hayro-ccitt",
@@ -3148,7 +3148,7 @@ checksum = "bc2d80da85f31c3fdc0366431f44cfd645a9da1e242ed1f4a61f213d9765660f"
[[package]]
name = "hayro-syntax"
version = "0.7.2"
source = "git+https://github.com/storytold/craft-libs?rev=d8dbfdcc2#d8dbfdcc20bb5f9a419815fc4392969e0e1a0ef0"
source = "git+https://github.com/storytold/craft-libs?rev=365bf47db#365bf47db64dc2ab88e7649548e9ab64b6644eda"
dependencies = [
"flate2",
"hayro-ccitt",
+25 -25
View File
@@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
rust-version = "1.95"
[workspace.dependencies]
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2", features = ["serde"] }
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db", features = ["serde"] }
# internal
photocraft-geom = { path = "crates/geom" }
photocraft-color = { path = "crates/color" }
@@ -18,11 +18,11 @@ photocraft-cms = { path = "crates/cms" }
photocraft-raster = { path = "crates/raster" }
photocraft-doc = { path = "crates/doc" }
photocraft-ops = { path = "crates/ops" }
photocraft-psd = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
photocraft-psd = { package = "craft-psd", git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
photocraft-codecs = { package = "craft-image-codecs", git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
photocraft-formats = { package = "craft-file-formats", git = "https://github.com/storytold/craft-libs", rev = "365bf47db", features = ["raster-codecs", "pdf", "svg", "ora", "kra", "xcf", "pdn", "raw", "psd", "affinity", "pcraft"] }
photocraft-raw = { path = "crates/raw" }
photocraft-affinity = { package = "craft-affinity", git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
photocraft-affinity = { package = "craft-affinity", git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
photocraft-compose = { path = "crates/compose" }
photocraft-gpu = { path = "crates/gpu" }
photocraft-paint = { path = "crates/paint" }
@@ -40,27 +40,27 @@ photocraft-tablet = { path = "crates/tablet" }
photocraft-ipp = { path = "crates/ipp" }
# external
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-print = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
# HEIC/HEIF: the shared decoder (replaces crates/heif; craft-libs#784).
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2", features = ["raster"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2", features = ["tree-render", "tree-render-system-fonts"] }
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-heif = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db", features = ["raster"] }
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-jpeg = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-pcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-pcraft-bundle = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-ora = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-kra = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-xcf = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-pdn = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db", features = ["tree-render", "tree-render-system-fonts"] }
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
# Interface translations: lookup, fallback, CLDR plurals and language names over the craft-i18n
# catalogs that `crates/ui-egui/build.rs` embeds from `CRAFT_I18N_DIR` (storytold/craft-i18n, at
# the commit in `craft-i18n.rev`). Already in the tree through craft-ui.
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
craft-i18n = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "d8dbfdcc2", features = ["egui"] }
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "365bf47db", features = ["egui"] }
thiserror = "2"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
@@ -220,7 +220,7 @@ egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "6d518fc7
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
# craft-pdf's vendored Hayro trees: consumers patch the same craft-libs revision (crates/pdf README).
hayro = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "d8dbfdcc2" }
hayro = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "365bf47db" }
+6 -11
View File
@@ -14,6 +14,10 @@ const MAX_BYTES: usize = 16 * 1024 * 1024;
const MAX_PIXELS: u64 = 24_000_000;
const PREFIX: usize = 44;
fn svg_metadata_limits() -> craft_svg::tree::Limits {
craft_svg::tree::Limits { bytes: MAX_BYTES, ..Default::default() }
}
/// Recognize native-vector payloads by content; names never authorize a preview.
pub fn is_native_source(source: &[u8]) -> bool {
source.starts_with(b"%PDF-") || source.starts_with(b"%!PS-Adobe-") || source.starts_with(&[0xc5, 0xd0, 0xd3, 0xc6])
@@ -46,13 +50,7 @@ pub fn frame_metadata(preview: &VectorPreview, expected_source_hash: [u8; 32]) -
return None;
}
let text = std::str::from_utf8(&preview.svg).ok()?;
let parsed = roxmltree::Document::parse(text).ok()?;
let root = parsed.root_element();
if root.tag_name().name() != "svg" {
return None;
}
let dimension = |key| root.attribute(key)?.parse::<f64>().ok();
let (width, height) = dimension("width").zip(dimension("height"))?;
let (width, height) = craft_svg::tree::root_unitless_size(text, &svg_metadata_limits()).ok()??;
(width.is_finite() && height.is_finite() && width > 0.0 && height > 0.0 && width <= 16384.0 && height <= 16384.0 && width * height <= MAX_PIXELS as f64)
.then_some((width, height))
}
@@ -68,10 +66,7 @@ pub fn frame(preview: &VectorPreview, source: &[u8]) -> Option<(f64, f64)> {
/// itself is the frame; non-finite, oversized or mismatched dimensions give `None`.
pub(crate) fn frame_for_svg(svg: &[u8], size: Size) -> Option<(f64, f64)> {
let text = std::str::from_utf8(svg).ok()?;
let parsed = roxmltree::Document::parse(text).ok()?;
let root = parsed.root_element();
let dimension = |key| root.attribute(key).and_then(|value| value.parse::<f64>().ok());
let Some((width, height)) = dimension("width").zip(dimension("height")) else {
let Some((width, height)) = craft_svg::tree::root_unitless_size(text, &svg_metadata_limits()).ok()? else {
// A general SVG may spell lengths in physical units. Its validated display canvas is
// the fallback; our normalized native previews always write unitless source pixels.
return Some((f64::from(size.width), f64::from(size.height)));