Use shared strict glTF URI percent decoding

This commit is contained in:
Dylan M. Taylor committed 2026-11-18 01:59:37 -05:00
1 parent 97f6b81984
commit d7739b0645
3 files changed
+22 -19

No files matched your search

Generated
+4 -3
View File
@@ -851,10 +851,11 @@ dependencies = [
[[package]]
name = "craft-mesh"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=b952ca0231867c8ad6749ac44cab5fc903c3ad52#b952ca0231867c8ad6749ac44cab5fc903c3ad52"
source = "git+https://github.com/storytold/craft-libs?rev=70e562aa88436b6b79a997215b4fa4f6a6b1838a#70e562aa88436b6b79a997215b4fa4f6a6b1838a"
dependencies = [
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b952ca0231867c8ad6749ac44cab5fc903c3ad52)",
"craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=70e562aa88436b6b79a997215b4fa4f6a6b1838a)",
"miniz_oxide 0.9.1",
"serde_json",
]
[[package]]
@@ -970,7 +971,7 @@ dependencies = [
[[package]]
name = "craft-zip"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=b952ca0231867c8ad6749ac44cab5fc903c3ad52#b952ca0231867c8ad6749ac44cab5fc903c3ad52"
source = "git+https://github.com/storytold/craft-libs?rev=70e562aa88436b6b79a997215b4fa4f6a6b1838a#70e562aa88436b6b79a997215b4fa4f6a6b1838a"
dependencies = [
"flate2",
"thiserror 2.0.21",
+1 -1
View File
@@ -73,7 +73,7 @@ craft-tcraft = { git = "https://github.com/storytold/craft-libs", rev = "c376774
# Isolated aligned writer; existing archive readers retain their pin and behavior.
craft-zip-usdz = { package = "craft-zip", git = "https://github.com/storytold/craft-libs", rev = "5631e99fe126cffb74c673eb458db04299f2bb9b" }
craft-zip = { git = "https://github.com/storytold/craft-libs", rev = "c376774f15ae7cd3b06a7ac664f01a8645af4b83" }
craft-mesh = { git = "https://github.com/storytold/craft-libs", rev = "b952ca0231867c8ad6749ac44cab5fc903c3ad52", default-features = false, features = ["stl", "ply", "fbx", "obj"] }
craft-mesh = { git = "https://github.com/storytold/craft-libs", rev = "70e562aa88436b6b79a997215b4fa4f6a6b1838a", default-features = false, features = ["stl", "ply", "fbx", "obj", "gltf"] }
craft-mcmat = { git = "https://github.com/storytold/craft-libs", rev = "c376774f15ae7cd3b06a7ac664f01a8645af4b83" }
# Who draws the window frame, and the app-drawn strip as the title bar (crates/ui-egui/src/titlebar.rs).
craft-window = { git = "https://github.com/storytold/craft-libs", rev = "390fe98b0dd3fb84db7c3af7cbd958db4e8cc585", features = ["egui"] }
+17 -15
View File
@@ -292,21 +292,23 @@ fn check_buffer_uris(doc: &gltf::Document) -> Result<()> {
}
pub(crate) fn percent_decode(s: &str) -> Option<String> {
let b = s.as_bytes();
let mut out = Vec::with_capacity(b.len());
let mut i = 0;
while let Some(&c) = b.get(i) {
let hex = |k: usize| b.get(k).and_then(|h| (*h as char).to_digit(16));
match (c, hex(i + 1), hex(i + 2)) {
(b'%', Some(h), Some(l)) => {
out.push((h * 16 + l) as u8);
i += 3;
}
_ => {
out.push(c);
i += 1;
}
craft_mesh::gltf::uri_decode_strict(s)
}
#[cfg(test)]
mod uri_decode_tests {
use super::percent_decode;
#[test]
fn strict_shared_uri_decoder_preserves_reference_policy() {
assert_eq!(percent_decode("texture%20é%2B.png"), Some("texture é+.png".into()));
assert_eq!(percent_decode("a+b%GG%2"), Some("a+b%GG%2".into()));
assert_eq!(percent_decode("%252e%252e"), Some("%2e%2e".into()));
// Decoding does not replace the external-reference confinement checks.
assert_eq!(percent_decode("%2e%2e%2fsecret"), Some("../secret".into()));
assert_eq!(percent_decode("%00"), Some("\0".into()));
for uri in ["%FF", "%C0%AF", "%ED%A0%80", "%E2%82"] {
assert_eq!(percent_decode(uri), None, "{uri}");
}
}
String::from_utf8(out).ok()
}