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.
This commit is contained in:
parent
971e1df148
commit
fedbd72d57
2 changed files with 25 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue