Skip to content

Commit

Permalink
osbuildexecutor: allow file type tar.TypeGNUSparse too
Browse files Browse the repository at this point in the history
We need to allow files of type `tar.TypeGNUSparse` in the result
that we get from the osbuild-worker-executor too.
  • Loading branch information
mvo5 authored and croissanne committed Jun 12, 2024
1 parent 971e1df commit fedbd72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/osbuildexecutor/runner-impl-aws-ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func validateOutputArchive(outputTarPath string) error {
}
// protect against someone smuggling in eg. device files
// XXX: should we support symlinks here?
if !slices.Contains([]byte{tar.TypeReg, tar.TypeDir}, hdr.Typeflag) {
if !slices.Contains([]byte{tar.TypeReg, tar.TypeDir, tar.TypeGNUSparse}, hdr.Typeflag) {
return fmt.Errorf("name %q must be a file/dir, is header type %q", hdr.Name, hdr.Typeflag)
}
// protect against executables, this implicitly protects
Expand Down
24 changes: 24 additions & 0 deletions internal/osbuildexecutor/runner-impl-aws-ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,35 @@ func TestValidateOutputArchiveHappy(t *testing.T) {
testTarPath := makeTestTarfile(t, map[*tar.Header]string{
&tar.Header{Name: "file1"}: "some content",
&tar.Header{Name: "path/to/file"}: "other content",
&tar.Header{
Name: "path/to/dir",
Typeflag: tar.TypeDir,
}: "",
})
err := osbuildexecutor.ValidateOutputArchive(testTarPath)
assert.NoError(t, err)
}

func makeSparseFile(t *testing.T, path string) {
output, err := exec.Command("truncate", "-s", "10M", path).CombinedOutput()
assert.Equal(t, "", string(output))
assert.NoError(t, err)
}

func TestValidateOutputArchiveHappySparseFile(t *testing.T) {
// go tar makes support for sparse files very hard, see also
// https://github.com/golang/go/issues/22735
tmpdir := t.TempDir()
makeSparseFile(t, filepath.Join(tmpdir, "big.img"))
testTarPath := filepath.Join(t.TempDir(), "test.tar")
output, err := exec.Command("tar", "--strip-components=1", "-C", tmpdir, "-c", "-S", "-f", testTarPath, "big.img").CombinedOutput()
assert.Equal(t, "", string(output))
assert.NoError(t, err)

err = osbuildexecutor.ValidateOutputArchive(testTarPath)
assert.NoError(t, err)
}

func TestValidateOutputArchiveSadDotDot(t *testing.T) {
testTarPath := makeTestTarfile(t, map[*tar.Header]string{
&tar.Header{Name: "file1/.."}: "some content",
Expand Down

0 comments on commit fedbd72

Please sign in to comment.