From fedbd72d57be0aaec895f14bdb1e7f382752d0ce Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 12 Jun 2024 14:41:51 +0200 Subject: [PATCH] osbuildexecutor: allow file type `tar.TypeGNUSparse` too We need to allow files of type `tar.TypeGNUSparse` in the result that we get from the osbuild-worker-executor too. --- .../osbuildexecutor/runner-impl-aws-ec2.go | 2 +- .../runner-impl-aws-ec2_test.go | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/osbuildexecutor/runner-impl-aws-ec2.go b/internal/osbuildexecutor/runner-impl-aws-ec2.go index 86277c34f..a68d8ea54 100644 --- a/internal/osbuildexecutor/runner-impl-aws-ec2.go +++ b/internal/osbuildexecutor/runner-impl-aws-ec2.go @@ -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 diff --git a/internal/osbuildexecutor/runner-impl-aws-ec2_test.go b/internal/osbuildexecutor/runner-impl-aws-ec2_test.go index 17ff2f431..ed36d6b89 100644 --- a/internal/osbuildexecutor/runner-impl-aws-ec2_test.go +++ b/internal/osbuildexecutor/runner-impl-aws-ec2_test.go @@ -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",