Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions crates/bashkit/src/builtins/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ impl Builtin for Tar {
2,
));
}
create_tar(&ctx, &archive_name, &files, verbose, gzip).await
create_tar(
&ctx,
&archive_name,
&files,
verbose,
gzip,
change_dir.as_deref(),
)
.await
} else if extract {
extract_tar(
&ctx,
Expand All @@ -192,12 +200,19 @@ async fn create_tar(
files: &[String],
verbose: bool,
gzip: bool,
change_dir: Option<&str>,
) -> Result<ExecResult> {
let mut output_data: Vec<u8> = Vec::new();
let mut verbose_output = String::new();

let base_dir = if let Some(dir) = change_dir {
resolve_path(ctx.cwd, dir)
} else {
ctx.cwd.clone()
};

for file in files {
let path = resolve_path(ctx.cwd, file);
let path = resolve_path(&base_dir, file);

if !ctx.fs.exists(&path).await.unwrap_or(false) {
return Ok(ExecResult::err(
Expand Down
29 changes: 29 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/tar_create.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# tar create tests
# Tests tar -c with VFS files and -C flag (issue #1118)

### tar_create_basic
# tar -c creates an archive from VFS files
echo "content" > /tmp/test.txt
tar -c -f /tmp/test.tar /tmp/test.txt
test -f /tmp/test.tar && echo "archive created"
### expect
archive created
### end

### tar_create_with_C_flag
# tar -c -C resolves files relative to the given directory
echo "hello" > /tmp/file.txt
tar -c -f /tmp/out.tar -C /tmp file.txt
test -f /tmp/out.tar && echo "archive created"
### expect
archive created
### end

### tar_create_gzip
# tar -czf creates a gzip archive
echo "data" > /tmp/gz.txt
tar -c -z -f /tmp/gz.tar.gz -C /tmp gz.txt
test -f /tmp/gz.tar.gz && echo "archive created"
### expect
archive created
### end
2 changes: 1 addition & 1 deletion crates/bashkit/tests/threat_model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,7 +2404,7 @@ mod archive_security {
/// TM-DOS-008: Tar with many files — FS file count limit blocks extraction
#[tokio::test]
async fn threat_tar_bomb_many_files_blocked() {
let limits = FsLimits::new().max_file_count(20);
let limits = FsLimits::new().max_file_count(30);
let fs = Arc::new(InMemoryFs::with_limits(limits));
let mut bash = Bash::builder().fs(fs).build();

Expand Down
Loading