From: Joe Tsai Date: Mon, 14 Aug 2017 23:14:08 +0000 (-0700) Subject: archive/tar: roundtrip reading device numbers X-Git-Tag: go1.10beta1~1573 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=17fa5a7c9f41bed796b5e236b517d0bf03a3f31d;p=gostls13.git archive/tar: roundtrip reading device numbers 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/archive/tar/reader.go b/src/archive/tar/reader.go index 21c0330420..98f6ea86fa 100644 --- a/src/archive/tar/reader.go +++ b/src/archive/tar/reader.go @@ -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 { diff --git a/src/archive/tar/reader_test.go b/src/archive/tar/reader_test.go index 3592a14842..79d271717c 100644 --- a/src/archive/tar/reader_test.go +++ b/src/archive/tar/reader_test.go @@ -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 index 0000000000..146e25b79d Binary files /dev/null and b/src/archive/tar/testdata/ustar-file-devs.tar differ