]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: narrow trim range for formatter'formatString
authorJes Cok <xigua67damn@gmail.com>
Mon, 12 Jun 2023 12:09:44 +0000 (12:09 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 1 Aug 2023 14:28:42 +0000 (14:28 +0000)
Trim s[:len(b)-1] rather than s[:len(b)], since s[len(b)-1] is '/'.

Change-Id: I055da555810c112774549bd13d4faa8bfa0a60dc
GitHub-Last-Rev: 457977514d75a6c72086c2f4d89fb601280b8b90
GitHub-Pull-Request: golang/go#60729
Reviewed-on: https://go-review.googlesource.com/c/go/+/502376
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/archive/tar/strconv.go

index ac3196370e61135f8c183e0d8dba442679f82edc..ac8105efadb4036cdeb027533a6d9c92fcb24f06 100644 (file)
@@ -73,7 +73,7 @@ func (f *formatter) formatString(b []byte, s string) {
        // in the V7 path field as a directory even though the full path
        // recorded elsewhere (e.g., via PAX record) contains no trailing slash.
        if len(s) > len(b) && b[len(b)-1] == '/' {
-               n := len(strings.TrimRight(s[:len(b)], "/"))
+               n := len(strings.TrimRight(s[:len(b)-1], "/"))
                b[n] = 0 // Replace trailing slash with NUL terminator
        }
 }