1
0
mirror of https://github.com/golang/go synced 2024-11-19 14:54:43 -07:00

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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Joe Tsai 2017-08-14 16:14:08 -07:00 committed by Joe Tsai
parent 0b06929b2d
commit 17fa5a7c9f
3 changed files with 13 additions and 4 deletions

View 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 {

View 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 {

Binary file not shown.