File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 8
8
"io/ioutil"
9
9
"os"
10
10
"path/filepath"
11
+ "strings"
11
12
"time"
12
13
"unsafe"
13
14
@@ -170,7 +171,7 @@ func (a *Archive) Offset() int64 {
170
171
171
172
// Name returns the name of the current entry as UTF-8 string
172
173
func (a * Archive ) Name () string {
173
- return unarrc .EntryGetName (a .archive )
174
+ return toValidName ( unarrc .EntryGetName (a .archive ) )
174
175
}
175
176
176
177
// RawName returns the name of the current entry as raw string
@@ -263,3 +264,14 @@ func (a *Archive) List() (contents []string, err error) {
263
264
264
265
return
265
266
}
267
+
268
+ func toValidName (name string ) string {
269
+ p := filepath .Clean (name )
270
+ if strings .HasPrefix (p , "/" ) {
271
+ p = p [len ("/" ):]
272
+ }
273
+ for strings .HasPrefix (p , "../" ) {
274
+ p = p [len ("../" ):]
275
+ }
276
+ return p
277
+ }
You can’t perform that action at this time.
0 commit comments