aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-getter/decompress.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/decompress.go')
-rw-r--r--vendor/github.com/hashicorp/go-getter/decompress.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/decompress.go b/vendor/github.com/hashicorp/go-getter/decompress.go
index d18174c..198bb0e 100644
--- a/vendor/github.com/hashicorp/go-getter/decompress.go
+++ b/vendor/github.com/hashicorp/go-getter/decompress.go
@@ -1,7 +1,15 @@
1package getter 1package getter
2 2
3import (
4 "strings"
5)
6
3// Decompressor defines the interface that must be implemented to add 7// Decompressor defines the interface that must be implemented to add
4// support for decompressing a type. 8// support for decompressing a type.
9//
10// Important: if you're implementing a decompressor, please use the
11// containsDotDot helper in this file to ensure that files can't be
12// decompressed outside of the specified directory.
5type Decompressor interface { 13type Decompressor interface {
6 // Decompress should decompress src to dst. dir specifies whether dst 14 // Decompress should decompress src to dst. dir specifies whether dst
7 // is a directory or single file. src is guaranteed to be a single file 15 // is a directory or single file. src is guaranteed to be a single file
@@ -16,14 +24,35 @@ var Decompressors map[string]Decompressor
16func init() { 24func init() {
17 tbzDecompressor := new(TarBzip2Decompressor) 25 tbzDecompressor := new(TarBzip2Decompressor)
18 tgzDecompressor := new(TarGzipDecompressor) 26 tgzDecompressor := new(TarGzipDecompressor)
27 txzDecompressor := new(TarXzDecompressor)
19 28
20 Decompressors = map[string]Decompressor{ 29 Decompressors = map[string]Decompressor{
21 "bz2": new(Bzip2Decompressor), 30 "bz2": new(Bzip2Decompressor),
22 "gz": new(GzipDecompressor), 31 "gz": new(GzipDecompressor),
32 "xz": new(XzDecompressor),
23 "tar.bz2": tbzDecompressor, 33 "tar.bz2": tbzDecompressor,
24 "tar.gz": tgzDecompressor, 34 "tar.gz": tgzDecompressor,
35 "tar.xz": txzDecompressor,
25 "tbz2": tbzDecompressor, 36 "tbz2": tbzDecompressor,
26 "tgz": tgzDecompressor, 37 "tgz": tgzDecompressor,
38 "txz": txzDecompressor,
27 "zip": new(ZipDecompressor), 39 "zip": new(ZipDecompressor),
28 } 40 }
29} 41}
42
43// containsDotDot checks if the filepath value v contains a ".." entry.
44// This will check filepath components by splitting along / or \. This
45// function is copied directly from the Go net/http implementation.
46func containsDotDot(v string) bool {
47 if !strings.Contains(v, "..") {
48 return false
49 }
50 for _, ent := range strings.FieldsFunc(v, isSlashRune) {
51 if ent == ".." {
52 return true
53 }
54 }
55 return false
56}
57
58func isSlashRune(r rune) bool { return r == '/' || r == '\\' }