]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: roundtrip reading device numbers
authorJoe Tsai <joetsai@digital-static.net>
Mon, 14 Aug 2017 23:14:08 +0000 (16:14 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 15 Aug 2017 00:54:37 +0000 (00:54 +0000)
Both GNU and BSD tar do not care if the devmajor and devminor values are
set on entries (like regular files) that aren't character or block devices.

While this is non-sensible, it is more consistent with the Writer to actually
read these fields always. In a vast majority of the cases these will still
be zero. In the rare situation where someone actually cares about these,
at least information was not silently lost.

Change-Id: I6e4ba01cd897a1b13c28b1837e102a4fdeb420ba
Reviewed-on: https://go-review.googlesource.com/55572
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/archive/tar/reader.go
src/archive/tar/reader_test.go
src/archive/tar/testdata/ustar-file-devs.tar [new file with mode: 0644]

index 21c0330420a1ca8ce418089757665463bbf6a4de..98f6ea86faab43e6505fdc12ed1a4daff40c27fe 100644 (file)
@@ -468,10 +468,8 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
                ustar := tr.blk.USTAR()
                hdr.Uname = p.parseString(ustar.UserName())
                hdr.Gname = p.parseString(ustar.GroupName())
-               if hdr.Typeflag == TypeChar || hdr.Typeflag == TypeBlock {
-                       hdr.Devmajor = p.parseNumeric(ustar.DevMajor())
-                       hdr.Devminor = p.parseNumeric(ustar.DevMinor())
-               }
+               hdr.Devmajor = p.parseNumeric(ustar.DevMajor())
+               hdr.Devminor = p.parseNumeric(ustar.DevMinor())
 
                var prefix string
                switch format {
index 3592a14842ecd1edf617dba1e7d819b40a20b15c..79d271717c1b01487c9334a1a1cac22fd0b6f506 100644 (file)
@@ -384,6 +384,17 @@ func TestReader(t *testing.T) {
                        Uid:     010000000,
                        ModTime: time.Unix(0, 0),
                }},
+       }, {
+               // USTAR archive with a regular entry with non-zero device numbers.
+               file: "testdata/ustar-file-devs.tar",
+               headers: []*Header{{
+                       Name:     "file",
+                       Mode:     0644,
+                       Typeflag: '0',
+                       ModTime:  time.Unix(0, 0),
+                       Devmajor: 1,
+                       Devminor: 1,
+               }},
        }}
 
        for _, v := range vectors {
diff --git a/src/archive/tar/testdata/ustar-file-devs.tar b/src/archive/tar/testdata/ustar-file-devs.tar
new file mode 100644 (file)
index 0000000..146e25b
Binary files /dev/null and b/src/archive/tar/testdata/ustar-file-devs.tar differ