fix(anatomy): R5.3 __proto__ field segments refused, seed identity guard over the whole seed tree, hashed id comparisons
This commit is contained in:
1 parent
3ece1a64b1
commit
f245b3ec25
7 files changed
+86
-33
No files matched your search
@@ -260,15 +260,35 @@ fn inside(folder: &Path, seed: &Path) -> bool {
|
||||
folder.starts_with(seed)
|
||||
}
|
||||
|
||||
/// Whether the seed folder is `folder` or one of its ancestors, by file identity (device and
|
||||
/// inode): a second path to the seed (a bind mount, a share mounted twice) is caught too.
|
||||
/// The file identities (device, inode) of the seed folder and of every folder under it, links
|
||||
/// never followed; `None` when the walk fails (the caller then refuses).
|
||||
fn seed_identities(seed: &Path) -> Option<Vec<(u64, u64)>> {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let mut identities = Vec::new();
|
||||
let mut pending = vec![seed.to_path_buf()];
|
||||
while let Some(folder) = pending.pop() {
|
||||
let metadata = fs::symlink_metadata(&folder).ok()?;
|
||||
identities.push((metadata.dev(), metadata.ino()));
|
||||
for entry in fs::read_dir(&folder).ok()? {
|
||||
let entry = entry.ok()?;
|
||||
if entry.file_type().ok()?.is_dir() {
|
||||
pending.push(entry.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(identities)
|
||||
}
|
||||
|
||||
/// Whether `folder` or one of its ancestors is the seed folder or a folder under it, by file
|
||||
/// identity: a second path to any of them (a bind mount, a share mounted twice on the same
|
||||
/// device) is caught too. A walk that fails counts as inside.
|
||||
fn inside_by_identity(folder: &Path, seed: &Path) -> bool {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let Ok(seed) = fs::metadata(seed) else {
|
||||
let Some(identities) = seed_identities(seed) else {
|
||||
return true;
|
||||
};
|
||||
folder.ancestors().any(|ancestor| {
|
||||
fs::metadata(ancestor).is_ok_and(|m| m.dev() == seed.dev() && m.ino() == seed.ino())
|
||||
fs::metadata(ancestor).is_ok_and(|m| identities.contains(&(m.dev(), m.ino())))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user