Skip to content

Commit b48afb4

Browse files
Ace-TangthaJeztah
authored andcommitted
fix: SCHILY.xattrs should be SCHILY.xattr
from golang code https://github.com/golang/go/blob/bad6b6fa9190e9079a6d6958859856a66f0fab87/src/archive/tar/common.go#L110 add unit test for tar xattr Fixes: #2863 Signed-off-by: Ace-Tang <[email protected]> (cherry picked from commit 6f944e4) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 9979a1a commit b48afb4

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

archive/tar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const (
100100
// readdir calls to this directory do not follow to lower layers.
101101
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
102102

103-
paxSchilyXattr = "SCHILY.xattrs."
103+
paxSchilyXattr = "SCHILY.xattr."
104104
)
105105

106106
// Apply applies a tar stream of an OCI style diff tar.

archive/tar_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"archive/tar"
2323
"bytes"
2424
"context"
25+
"fmt"
2526
"io"
2627
"io/ioutil"
2728
"os"
@@ -32,6 +33,7 @@ import (
3233

3334
_ "crypto/sha256"
3435

36+
"github.com/containerd/containerd/testutil"
3537
"github.com/containerd/continuity/fs"
3638
"github.com/containerd/continuity/fs/fstest"
3739
"github.com/pkg/errors"
@@ -182,6 +184,50 @@ func TestSymlinks(t *testing.T) {
182184
}
183185
}
184186

187+
func TestTarWithXattr(t *testing.T) {
188+
testutil.RequiresRoot(t)
189+
190+
fileXattrExist := func(f1, xattrKey, xattrValue string) func(string) error {
191+
return func(root string) error {
192+
values, err := getxattr(filepath.Join(root, f1), xattrKey)
193+
if err != nil {
194+
return err
195+
}
196+
if xattrValue != string(values) {
197+
return fmt.Errorf("file xattrs expect to be %s, actually get %s", xattrValue, values)
198+
}
199+
return nil
200+
}
201+
}
202+
203+
tests := []struct {
204+
name string
205+
key string
206+
value string
207+
err error
208+
}{
209+
{
210+
name: "WithXattrsUser",
211+
key: "user.key",
212+
value: "value",
213+
},
214+
{
215+
// security related xattrs need root permission to test
216+
name: "WithXattrSelinux",
217+
key: "security.selinux",
218+
value: "unconfined_u:object_r:default_t:s0\x00",
219+
},
220+
}
221+
for _, at := range tests {
222+
tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC()).WithXattrs(map[string]string{
223+
at.key: at.value,
224+
})
225+
w := TarAll(tc.File("/file", []byte{}, 0755))
226+
validator := fileXattrExist("file", at.key, at.value)
227+
t.Run(at.name, makeWriterToTarTest(w, nil, validator, at.err))
228+
}
229+
}
230+
185231
func TestBreakouts(t *testing.T) {
186232
tc := TarContext{}.WithUIDGID(os.Getuid(), os.Getgid()).WithModTime(time.Now().UTC())
187233
expected := "unbroken"

0 commit comments

Comments
 (0)