]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: fix parsePAX to be POSIX.1-2001 compliant
authorJoe Tsai <joetsai@digital-static.net>
Tue, 18 Oct 2016 23:57:02 +0000 (16:57 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Wed, 19 Oct 2016 18:39:30 +0000 (18:39 +0000)
Relevant PAX specification:
<<<
If the <value> field is zero length, it shall delete any header
block field, previously entered extended header value, or
global extended header value of the same name.
>>>

We don't delete global extender headers since the Reader doesn't
even support global headers (which the specification admits was
a controversial feature).

Change-Id: I2125a5c907b23a3dc439507ca90fa5dc47d474a9
Reviewed-on: https://go-review.googlesource.com/31440
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/archive/tar/reader.go
src/archive/tar/reader_test.go

index 5fb0b3df964eba7a6e9ae3e37a28a2668abf1237..0d60d23b8b68db55d598717a88651b6fe5e880c2 100644 (file)
@@ -363,8 +363,13 @@ func parsePAX(r io.Reader) (map[string]string, error) {
                        sparseMap.WriteString(value)
                        sparseMap.Write([]byte{','})
                } else {
-                       // Normal key. Set the value in the headers map.
-                       headers[keyStr] = value
+                       // According to PAX specification, a value is stored only if it is
+                       // non-empty. Otherwise, the key is deleted.
+                       if len(value) > 0 {
+                               headers[key] = value
+                       } else {
+                               delete(headers, key)
+                       }
                }
        }
        if sparseMap.Len() != 0 {
index 7d73be22322b797f2f37650d65b5e8d12fca3f2e..b315af5ec3e3d183a7f402694345440dadb2816d 100644 (file)
@@ -1072,6 +1072,8 @@ func TestParsePAX(t *testing.T) {
                        map[string]string{"GNU.sparse.map": "0,1,2,3"}, true},
                {"13 key1=haha\n13 key2=nana\n13 key3=kaka\n",
                        map[string]string{"key1": "haha", "key2": "nana", "key3": "kaka"}, true},
+               {"13 key1=val1\n13 key2=val2\n8 key1=\n",
+                       map[string]string{"key2": "val2"}, true},
        }
 
        for i, v := range vectors {