From 4c55774304e5c6aecae55839ca34981acccebd85 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 14 Aug 2017 17:16:52 -0700 Subject: [PATCH] archive/tar: re-implement USTAR path splitting The logic for USTAR was disabled because a previous implementation of Writer had a wrong understanding of the differences between USTAR and GNU, causing the prefix field is incorrectly be populated in GNU files. Now that this issue has been fixed, we can re-enable the logic for USTAR path splitting, which allows Writer to use the USTAR for a wider range of possible inputs. Updates #9683 Updates #12594 Updates #17630 Change-Id: I9fe34e5df63f99c6dd56fee3a7e7e4d6ec3995c9 Reviewed-on: https://go-review.googlesource.com/55574 Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/archive/tar/common.go | 8 ++++--- src/archive/tar/testdata/ustar.issue12594.tar | Bin 3072 -> 0 bytes src/archive/tar/writer.go | 20 ++++++++++++------ src/archive/tar/writer_test.go | 12 +++-------- 4 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 src/archive/tar/testdata/ustar.issue12594.tar diff --git a/src/archive/tar/common.go b/src/archive/tar/common.go index 6390ca41c6..b1704a402d 100644 --- a/src/archive/tar/common.go +++ b/src/archive/tar/common.go @@ -86,6 +86,7 @@ func (h *Header) allowedFormats() (format int, paxHdrs map[string]string) { paxHdrs = make(map[string]string) verifyString := func(s string, size int, gnuLong bool, paxKey string) { + // NUL-terminator is optional for path and linkpath. // Technically, it is required for uname and gname, // but neither GNU nor BSD tar checks for it. @@ -95,9 +96,10 @@ func (h *Header) allowedFormats() (format int, paxHdrs map[string]string) { format &^= formatGNU // No GNU } if !isASCII(s) || tooLong { - // TODO(dsnet): If the path is splittable, it is possible to still - // use the USTAR format. - format &^= formatUSTAR // No USTAR + canSplitUSTAR := paxKey == paxPath + if _, _, ok := splitUSTARPath(s); !canSplitUSTAR || !ok { + format &^= formatUSTAR // No USTAR + } if paxKey == paxNone { format &^= formatPAX // No PAX } else { diff --git a/src/archive/tar/testdata/ustar.issue12594.tar b/src/archive/tar/testdata/ustar.issue12594.tar deleted file mode 100644 index 64931bfbe17187372266b90aee763b6a8d5dd803..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3072 zcmeH{K?=hl5Jg@06gffa=xA0wj0>#=Yf57w$FD}RtdK=SinCGq12g{d>1KcT>Zz~p zybaAkeyo&n*tL{GC