Merge pull request #4104 from philaris/fix_max_uint32_uid_gid_to_zero

in tar dump, convert uid, gid of value -1 to zero
This commit is contained in:
Michael Eischer 2023-01-02 22:28:28 +01:00 committed by GitHub
commit 89a8006578
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,9 @@
Bugfix: fix restic dump of tar file with 32-bit binary
When using a 32-bit build of restic, the `restic dump` command could in some
cases create tar files containing negative uid and gid. These files cannot be
read by gnu tar. This corner case especially applies to backups from stdin on Windows.
We have changed the dump command to create valid tar files in this case.
https://github.com/restic/restic/issues/4103
https://github.com/restic/restic/pull/4104

View file

@ -38,6 +38,15 @@ const (
cISVTX = 0o1000 // Save text (sticky bit)
)
// in a 32-bit build of restic:
// substitute a uid or gid of -1 (which was converted to 2^32 - 1) with 0
func tarIdentifier(id uint32) int {
if int(id) == -1 {
return 0
}
return int(id)
}
func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writer) error {
relPath, err := filepath.Rel("/", node.Path)
if err != nil {
@ -48,8 +57,8 @@ func (d *Dumper) dumpNodeTar(ctx context.Context, node *restic.Node, w *tar.Writ
Name: filepath.ToSlash(relPath),
Size: int64(node.Size),
Mode: int64(node.Mode.Perm()), // cIS* constants are added later
Uid: int(node.UID),
Gid: int(node.GID),
Uid: tarIdentifier(node.UID),
Gid: tarIdentifier(node.GID),
Uname: node.User,
Gname: node.Group,
ModTime: node.ModTime,