Skip to content

Commit a58a00e

Browse files
authored
Merge pull request #30 from saracen/extraction-improvements
Extraction improvements
2 parents b471a36 + f0b3e05 commit a58a00e

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

archiver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (a *Archiver) Archive(ctx context.Context, files map[string]os.FileInfo) (e
136136
return err
137137
}
138138

139-
if !strings.HasPrefix(path, a.chroot) {
139+
if !strings.HasPrefix(path, a.chroot+string(filepath.Separator)) && path != a.chroot {
140140
return fmt.Errorf("%s cannot be archived from outside of chroot (%s)", name, a.chroot)
141141
}
142142

extractor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (e *Extractor) Extract(ctx context.Context) (err error) {
143143
return err
144144
}
145145

146-
if !strings.HasPrefix(path, e.chroot) {
146+
if !strings.HasPrefix(path, e.chroot+string(filepath.Separator)) && path != e.chroot {
147147
return fmt.Errorf("%s cannot be extracted outside of chroot (%s)", path, e.chroot)
148148
}
149149

go.mod

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/saracen/fastzip
33
go 1.13
44

55
require (
6-
github.com/klauspost/compress v1.11.3
6+
github.com/klauspost/compress v1.13.5
77
github.com/saracen/zipextra v0.0.0-20201205103923-7347a2ee3f10
8-
github.com/stretchr/testify v1.6.1
9-
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520
10-
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634
8+
github.com/stretchr/testify v1.7.0
9+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
10+
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf
1111
)

go.sum

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/klauspost/compress v1.11.2 h1:MiK62aErc3gIiVEtyzKfeOHgW7atJb5g/KNX5m3c2nQ=
4-
github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
5-
github.com/klauspost/compress v1.11.3 h1:dB4Bn0tN3wdCzQxnS8r06kV74qN/TAfaIS0bVE8h3jc=
6-
github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
3+
github.com/klauspost/compress v1.13.5 h1:9O69jUPDcsT9fEm74W92rZL9FQY7rCdaXVneq+yyzl4=
4+
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
75
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
86
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9-
github.com/saracen/zipextra v0.0.0-20191018034721-f8fcc2e1b58e h1:psyRxwoYbvGxzM8WucxDD5TJ994ePVteYpeb4BIZVic=
10-
github.com/saracen/zipextra v0.0.0-20191018034721-f8fcc2e1b58e/go.mod h1:6Zk1rDeZXl7t6qPppqntIzWu6A+k9OYmT1LzehKE6e0=
117
github.com/saracen/zipextra v0.0.0-20201205103923-7347a2ee3f10 h1:UdM0Zmjq5MlMEnSu1M+dbJI6/YwlNLiO6p+IJJ3au4A=
128
github.com/saracen/zipextra v0.0.0-20201205103923-7347a2ee3f10/go.mod h1:6Zk1rDeZXl7t6qPppqntIzWu6A+k9OYmT1LzehKE6e0=
13-
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
149
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
16-
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
17-
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 h1:Bx6FllMpG4NWDOfhMBz1VR2QYNp/SAOHPIAsaVmxfPo=
18-
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
19-
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 h1:bNEHhJCnrwMKNMmOx3yAynp5vs5/gRy+XWFtZFu7NBM=
20-
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
10+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
11+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
12+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
13+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
14+
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
15+
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2116
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2217
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2318
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

register.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fastzip
22

33
import (
4+
"bufio"
45
"io"
56
"sync"
67

@@ -19,18 +20,20 @@ type flater interface {
1920
func newFlateReaderPool(newReaderFn func(w io.Reader) io.ReadCloser) *sync.Pool {
2021
pool := &sync.Pool{}
2122
pool.New = func() interface{} {
22-
return &flateReader{pool, newReaderFn(nil)}
23+
return &flateReader{pool, bufio.NewReaderSize(nil, 32*1024), newReaderFn(nil)}
2324
}
2425
return pool
2526
}
2627

2728
type flateReader struct {
2829
pool *sync.Pool
30+
buf *bufio.Reader
2931
io.ReadCloser
3032
}
3133

3234
func (fr *flateReader) Reset(r io.Reader) {
33-
fr.ReadCloser.(flate.Resetter).Reset(r, nil)
35+
fr.buf.Reset(r)
36+
fr.ReadCloser.(flate.Resetter).Reset(fr.buf, nil)
3437
}
3538

3639
func (fr *flateReader) Close() error {

0 commit comments

Comments
 (0)