diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2016-10-18 17:22:25 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-10-22 16:35:14 +0000 |
| commit | 3d4ea227c6b8062c436fc9417034f2d01cf8c82c (patch) | |
| tree | b2627d511a6f6e7aaa225d132ea15d16592a05fb /src/archive/tar/reader_test.go | |
| parent | ece4e23d9aaed3e11f7a0b9a3f15c592c96b065d (diff) | |
| download | go-3d4ea227c6b8062c436fc9417034f2d01cf8c82c.tar.xz | |
archive/tar: validate sparse headers in parsePAX
According to the GNU manual, the format is:
<<<
GNU.sparse.size=size
GNU.sparse.numblocks=numblocks
repeat numblocks times
GNU.sparse.offset=offset
GNU.sparse.numbytes=numbytes
end repeat
>>>
The logic in parsePAX converts the repeating sequence of
(offset, numbytes) pairs (which is not PAX compliant) into a single
comma-delimited list of numbers (which is now PAX compliant).
Thus, we validate the following:
* The (offset, numbytes) headers must come in the correct order.
* The ',' delimiter cannot appear in the value.
We do not validate that the value is a parsible decimal since that
will be determined later.
Change-Id: I8d6681021734eb997898227ae8603efb1e17c0c8
Reviewed-on: https://go-review.googlesource.com/31439
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/archive/tar/reader_test.go')
| -rw-r--r-- | src/archive/tar/reader_test.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/archive/tar/reader_test.go b/src/archive/tar/reader_test.go index b315af5ec3..338686836b 100644 --- a/src/archive/tar/reader_test.go +++ b/src/archive/tar/reader_test.go @@ -1067,13 +1067,20 @@ func TestParsePAX(t *testing.T) { {"30 mtime=1350244992.023960108\n", map[string]string{"mtime": "1350244992.023960108"}, true}, {"3 somelongkey=\n", nil, false}, {"50 tooshort=\n", nil, false}, - {"23 GNU.sparse.offset=0\n25 GNU.sparse.numbytes=1\n" + - "23 GNU.sparse.offset=2\n25 GNU.sparse.numbytes=3\n", - 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}, + {"22 GNU.sparse.size=10\n26 GNU.sparse.numblocks=2\n" + + "23 GNU.sparse.offset=1\n25 GNU.sparse.numbytes=2\n" + + "23 GNU.sparse.offset=3\n25 GNU.sparse.numbytes=4\n", + map[string]string{paxGNUSparseSize: "10", paxGNUSparseNumBlocks: "2", paxGNUSparseMap: "1,2,3,4"}, true}, + {"22 GNU.sparse.size=10\n26 GNU.sparse.numblocks=1\n" + + "25 GNU.sparse.numbytes=2\n23 GNU.sparse.offset=1\n", + nil, false}, + {"22 GNU.sparse.size=10\n26 GNU.sparse.numblocks=1\n" + + "25 GNU.sparse.offset=1,2\n25 GNU.sparse.numbytes=2\n", + nil, false}, } for i, v := range vectors { |
