]> Cypherpunks repositories - gostls13.git/commit
archive/tar: check for permissible output formats first
authorJoe Tsai <joetsai@digital-static.net>
Wed, 9 Aug 2017 20:12:50 +0000 (13:12 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Fri, 11 Aug 2017 04:39:39 +0000 (04:39 +0000)
commitead6255ce3bd39e56d66f39471ab1854fd4f67f2
tree165241c255ea2d46a442b65aa1015f82406edbc7
parent49ab0dba561ba1abd8b6b001789a155f47a8cb34
archive/tar: check for permissible output formats first

The current logic in writeHeader attempts to encode the Header in one
format and if it discovered that it could not it would attempt to
switch to a different format mid-way through. This makes it very
hard to reason about what format will be used in the end and whether
it will even be a valid format.

Instead, we should verify from the start what formats are allowed
to encode the given input Header. If no formats are possible,
then we can return immediately, rejecting the Header.

For now, we continue on to the hairy logic in writeHeader, but
a future CL can split that logic up and specialize them for each
format now that we know what is possible.

Update #9683
Update #12594

Change-Id: I8406ea855dfcb8b478a03a7058ddf8b2b09d46dc
Reviewed-on: https://go-review.googlesource.com/54433
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/archive/tar/common.go
src/archive/tar/tar_test.go
src/archive/tar/writer.go