@@ -83,8 +83,7 @@ func testZipArchive(t *testing.T, context spec.G, it spec.S) {
83
83
})
84
84
85
85
it ("unpackages the archive into the path" , func () {
86
- var err error
87
- err = zipArchive .Decompress (tempDir )
86
+ err := zipArchive .Decompress (tempDir )
88
87
Expect (err ).ToNot (HaveOccurred ())
89
88
90
89
files , err := filepath .Glob (fmt .Sprintf ("%s/*" , tempDir ))
@@ -114,8 +113,7 @@ func testZipArchive(t *testing.T, context spec.G, it spec.S) {
114
113
})
115
114
116
115
it ("unpackages the archive into the path but also strips the first component" , func () {
117
- var err error
118
- err = zipArchive .StripComponents (1 ).Decompress (tempDir )
116
+ err := zipArchive .StripComponents (1 ).Decompress (tempDir )
119
117
Expect (err ).ToNot (HaveOccurred ())
120
118
121
119
files , err := filepath .Glob (fmt .Sprintf ("%s/*" , tempDir ))
@@ -128,6 +126,38 @@ func testZipArchive(t *testing.T, context spec.G, it spec.S) {
128
126
Expect (filepath .Join (tempDir , "some-other-dir" , "some-file" )).To (BeARegularFile ())
129
127
})
130
128
129
+ context ("when given a zip file with enough contents to exhaust file descriptors" , func () {
130
+ it .Before (func () {
131
+ buffer := bytes .NewBuffer (nil )
132
+ zw := zip .NewWriter (buffer )
133
+
134
+ // Linux and MacOS seem to have artificially low limits like 1024 and
135
+ // 256 respectively. Using a value like 2048 should be high enough to
136
+ // trigger the limit on both.
137
+ for i := 0 ; i < 2048 ; i ++ {
138
+ name := fmt .Sprintf ("some-file-%d" , i )
139
+
140
+ header := & zip.FileHeader {Name : name }
141
+ header .SetMode (0755 )
142
+
143
+ file , err := zw .CreateHeader (header )
144
+ Expect (err ).NotTo (HaveOccurred ())
145
+
146
+ _ , err = file .Write ([]byte (name ))
147
+ Expect (err ).NotTo (HaveOccurred ())
148
+ }
149
+
150
+ Expect (zw .Close ()).To (Succeed ())
151
+
152
+ zipArchive = vacation .NewZipArchive (bytes .NewReader (buffer .Bytes ()))
153
+ })
154
+
155
+ it ("closes file descriptors as it goes" , func () {
156
+ err := zipArchive .Decompress (tempDir )
157
+ Expect (err ).ToNot (HaveOccurred ())
158
+ })
159
+ })
160
+
131
161
context ("failure cases" , func () {
132
162
context ("when it fails to create a zip reader" , func () {
133
163
it ("returns an error" , func () {
@@ -140,12 +170,12 @@ func testZipArchive(t *testing.T, context spec.G, it spec.S) {
140
170
141
171
context ("when a file is not inside of the destination director (Zip Slip)" , func () {
142
172
var buffer * bytes.Buffer
173
+
143
174
it .Before (func () {
144
- var err error
145
175
buffer = bytes .NewBuffer (nil )
146
176
zw := zip .NewWriter (buffer )
147
177
148
- _ , err = zw .Create (filepath .Join (".." , "some-dir" ))
178
+ _ , err : = zw .Create (filepath .Join (".." , "some-dir" ))
149
179
Expect (err ).NotTo (HaveOccurred ())
150
180
151
181
Expect (zw .Close ()).To (Succeed ())
0 commit comments