Skip to content

Commit 6fc79fe

Browse files
committed
tar: Don't filter out toplevel /run, /proc etc
Otherwise we break things when using this code to process a "non-ostree" image. Signed-off-by: Colin Walters <[email protected]>
1 parent 993a583 commit 6fc79fe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/src/tar/write.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,12 @@ fn normalize_validate_path<'a>(
182182
ret.push(camino::Utf8Component::CurDir);
183183
}
184184
let mut found_first = false;
185+
let mut excluded = false;
185186
for part in components {
186187
let part = part?;
188+
if excluded {
189+
return Ok(NormalizedPathResult::Filtered(part.as_str()));
190+
}
187191
if !found_first {
188192
if let Utf8Component::Normal(part) = part {
189193
found_first = true;
@@ -203,7 +207,10 @@ fn normalize_validate_path<'a>(
203207
}
204208
}
205209
o if EXCLUDED_TOPLEVEL_PATHS.contains(&o) => {
206-
return Ok(NormalizedPathResult::Filtered(part));
210+
// We don't want to actually drop the toplevel, but mark
211+
// *children* of it as excluded.
212+
excluded = true;
213+
ret.push(part)
207214
}
208215
_ if config.allow_nonusr => ret.push(part),
209216
_ => {
@@ -516,6 +523,8 @@ mod tests {
516523
("usr///share/.//blah", "./usr/share/blah"),
517524
("var/lib/blah", "./usr/share/factory/var/lib/blah"),
518525
("./var/lib/blah", "./usr/share/factory/var/lib/blah"),
526+
("dev", "./dev"),
527+
("/proc", "./proc"),
519528
("./", "."),
520529
];
521530
let valid_nonusr = &[("boot", "./boot"), ("opt/puppet/blah", "./opt/puppet/blah")];

lib/tests/it/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ async fn test_tar_write() -> Result<()> {
395395
.run()?;
396396
assert_eq!(r.filtered.len(), 1);
397397
assert!(r.filtered.get("var").is_none());
398-
assert_eq!(*r.filtered.get("run").unwrap(), 2);
398+
// TODO: change filter_tar to properly make this run/somefile, but eh...we're
399+
// just going to accept this stuff in the future but ignore it anyways.
400+
assert_eq!(*r.filtered.get("somefile").unwrap(), 1);
399401

400402
Ok(())
401403
}

0 commit comments

Comments
 (0)