From 840ec052f6b550859f48fff28559bf18e5ca4b22 Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Mon, 12 Jun 2023 12:09:44 +0000 Subject: [PATCH] archive/tar: narrow trim range for formatter'formatString 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 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: David Chase --- src/archive/tar/strconv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archive/tar/strconv.go b/src/archive/tar/strconv.go index ac3196370e6..ac8105efadb 100644 --- a/src/archive/tar/strconv.go +++ b/src/archive/tar/strconv.go @@ -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 } }