]> Cypherpunks repositories - gostls13.git/commit
archive/tar: detect truncated files
authorJoe Tsai <joetsai@digital-static.net>
Thu, 1 Oct 2015 09:30:29 +0000 (02:30 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 6 Nov 2015 04:31:26 +0000 (04:31 +0000)
commite3b615fd6c633a05a5d4d46cc0345fdfb82c28e6
tree48770f21b2f5b46d914472265cc4f40d02d51435
parent6083bd65f7a8e621efe9b6381c040ffab7f8d189
archive/tar: detect truncated files

Motivation:
* Reader.skipUnread never reports io.ErrUnexpectedEOF. This is strange
given that io.ErrUnexpectedEOF is given through Reader.Read if the
user manually reads the file.
* Reader.skipUnread fails to detect truncated files since io.Seeker
is lazy about reporting errors. Thus, the behavior of Reader differs
whether the input io.Reader also satisfies io.Seeker or not.

To solve this, we seek to one before the end of the data section and
always rely on at least one call to io.CopyN. If the tr.r satisfies
io.Seeker, this is guarunteed to never read more than blockSize.

Fixes #12557

Change-Id: I0ddddfc6bed0d74465cb7e7a02b26f1de7a7a279
Reviewed-on: https://go-review.googlesource.com/15175
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/archive/tar/reader.go
src/archive/tar/reader_test.go
src/archive/tar/testdata/pax-path-hdr.tar [new file with mode: 0644]
src/archive/tar/testdata/ustar-file-reg.tar [new file with mode: 0644]