mirror of
https://github.com/moby/moby.git
synced 2026-08-03 06:30:59 +00:00
Merge pull request #49152 from thaJeztah/pkg_archive_nolookups
pkg/archive: nosysFileInfo: implement tar.FileInfoNames to prevent lookups
This commit is contained in:
@@ -472,13 +472,35 @@ func (compression *Compression) Extension() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// assert that we implement [tar.FileInfoNames].
|
||||
//
|
||||
// TODO(thaJeztah): disabled to allow compiling on < go1.23. un-comment once we drop support for older versions of go.
|
||||
// var _ tar.FileInfoNames = (*nosysFileInfo)(nil)
|
||||
|
||||
// nosysFileInfo hides the system-dependent info of the wrapped FileInfo to
|
||||
// prevent tar.FileInfoHeader from introspecting it and potentially calling into
|
||||
// glibc.
|
||||
//
|
||||
// It implements [tar.FileInfoNames] to further prevent [tar.FileInfoHeader]
|
||||
// from performing any lookups on go1.23 and up. see https://go.dev/issue/50102
|
||||
type nosysFileInfo struct {
|
||||
os.FileInfo
|
||||
}
|
||||
|
||||
// Uname stubs out looking up username. It implements [tar.FileInfoNames]
|
||||
// to prevent [tar.FileInfoHeader] from loading libraries to perform
|
||||
// username lookups.
|
||||
func (fi nosysFileInfo) Uname() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Gname stubs out looking up group-name. It implements [tar.FileInfoNames]
|
||||
// to prevent [tar.FileInfoHeader] from loading libraries to perform
|
||||
// username lookups.
|
||||
func (fi nosysFileInfo) Gname() (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (fi nosysFileInfo) Sys() interface{} {
|
||||
// A Sys value of type *tar.Header is safe as it is system-independent.
|
||||
// The tar.FileInfoHeader function copies the fields into the returned
|
||||
|
||||
Reference in New Issue
Block a user