Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix clipboard read-policy bypass and lock-held file checks

Dylan M. Taylor42f8b513a294
diff --git a/apps/vectorcraft/src/clipboard.rs b/apps/vectorcraft/src/clipboard.rs
index c749cadcc..957d302d5 100644
--- a/apps/vectorcraft/src/clipboard.rs
+++ b/apps/vectorcraft/src/clipboard.rs
@@ -144,7 +144,12 @@ fn copied_file(paths: Vec<PathBuf>, mimes: &[&'static str]) -> Option<Flavour> {
_ => path,
};
// A paste sent by automation reads only what its roots allow.
- vectorcraft_engine::file_access::check_read(&path.to_string_lossy()).ok()?;
+ match path.to_str() {
+ Some(p) => vectorcraft_engine::file_access::check_read(p).ok()?,
+ // A lossy name would check another file than the one opened.
+ None if vectorcraft_engine::file_access::current().is_none() => {}
+ None => return None,
+ }
let mut head = Vec::with_capacity(FILE_HEAD);
std::fs::File::open(&path).ok()?.take(FILE_HEAD as u64).read_to_end(&mut head).ok()?;
let mime = file_flavour(&path.to_string_lossy(), &head, mimes)?;
diff --git a/crates/doc/src/placed_document.rs b/crates/doc/src/placed_document.rs
index 8de94bdfd..a94edf42a 100644
--- a/crates/doc/src/placed_document.rs
+++ b/crates/doc/src/placed_document.rs
@@ -320,7 +320,10 @@ pub fn full_bytes_cached(p: &PlacedDocument, blob: &ImageBlob) -> Option<Arc<Vec
return Some(blob.bytes.clone());
}
let allowed = |path: &str| READ_CHECK.get().is_none_or(|ok| ok(path));
- full().iter().rev().find(|(k, path, _)| *k == p.key && allowed(path)).map(|(_, _, b)| b.clone())
+ // Copy the candidates, newest first, so the filesystem checks run without the lock.
+ let candidates: Vec<(String, Arc<Vec<u8>>)> =
+ full().iter().rev().filter(|(k, _, _)| *k == p.key).map(|(_, path, b)| (path.clone(), b.clone())).collect();
+ candidates.into_iter().find(|(path, _)| allowed(path)).map(|(_, b)| b)
}
/// The file's bytes: stored, read again already, or read again now ([`set_file_reader`]). `None`