• Joe Tsai's avatar
    archive/tar: add support for long binary strings in GNU format · 5c20ffbb
    Joe Tsai authored
    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/55573Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    5c20ffbb
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...