]> Cypherpunks repositories - gostls13.git/commit
archive/tar: add support for long binary strings in GNU format
authorJoe Tsai <joetsai@digital-static.net>
Mon, 14 Aug 2017 23:44:15 +0000 (16:44 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Wed, 16 Aug 2017 00:39:32 +0000 (00:39 +0000)
commit5c20ffbb2f8ede35af7700797281248c71968286
tree9a2799d9cfc7874177a218094835a367e907047d
parentd6cada7fa4ef92190c2b59c9048413f9280e4a74
archive/tar: add support for long binary strings in GNU format

The GNU tar format defines the following type flags:
TypeGNULongName = 'L' // Next file has a long name
TypeGNULongLink = 'K' // Next file symlinks to a file w/ a long name

Anytime a string exceeds the field dedicated to store it, the GNU format
permits a fake "file" to be prepended where that file entry has a Typeflag
of 'L' or 'K' and the contents of the file is a NUL-terminated string.

Contrary to previous TODO comments,
the GNU format supports arbitrary strings (without NUL) rather UTF-8 strings.
The manual says the following:
<<<
The name, linkname, magic, uname, and gname are
null-terminated character strings
>>>
<<<
All characters in header blocks are represented
by using 8-bit characters in the local variant of ASCII.
>>>

From this description, we gather the following:
* We must forbid NULs in any GNU strings
* Any 8-bit value (other than NUL) is permitted

Since the modern world has moved to UTF-8, it is really difficult to
determine what a "local variant of ASCII" means. For this reason,
we treat strings as just an arbitrary binary string (without NUL)
and leave it to the user to determine the encoding of this string.
(Practically, it seems that UTF-8 is the typical encoding used
in GNU archives seen in the wild).

The implementation of GNU tar seems to confirm this interpretation
of the manual where it permits any arbitrary binary string to exist
within these fields so long as they do not contain the NUL character.

 $ touch `echo -e "not\x80\x81\x82\x83utf8"`
 $ gnutar -H gnu --tar -cvf gnu-not-utf8.tar $(echo -e "not\x80\x81\x82\x83utf8")

The fact that we permit arbitrary binary in GNU strings goes
hand-in-hand with the fact that GNU also permits a "base-256" encoding
of numeric fields, which is effectively two-complement binary.

Change-Id: Ic037ec6bed306d07d1312f0058594bd9b64d9880
Reviewed-on: https://go-review.googlesource.com/55573
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/archive/tar/common.go
src/archive/tar/reader_test.go
src/archive/tar/strconv.go
src/archive/tar/tar_test.go
src/archive/tar/testdata/gnu-not-utf8.tar [new file with mode: 0644]
src/archive/tar/testdata/gnu-utf8.tar [new file with mode: 0644]
src/archive/tar/writer.go
src/archive/tar/writer_test.go