rubyzip 3.7.0 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Changelog.md +10 -0
- data/README.md +10 -0
- data/lib/zip/central_directory.rb +23 -0
- data/lib/zip/crypto/decrypted_io.rb +28 -6
- data/lib/zip/inflater.rb +1 -1
- data/lib/zip/input_stream.rb +37 -10
- data/lib/zip/version.rb +1 -1
- data/lib/zip.rb +3 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fa293a78a017a755509e78a2e0d744dadfdbe3cd5a9c9a4f5e1c03d3a3aee4fc
|
|
4
|
+
data.tar.gz: 1565096ff4a01f28427adf39169d28f7b1e6d85c281c1b1cee15f2eb96576590
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91ad34779985c013032768ed9bbe5bf545273374d9ecc6dc6f5fe142c1f0293909da37a26c17e56a6a0338b97b6870fe298a10c8c590b1a2b3b25b4631ffcc91
|
|
7
|
+
data.tar.gz: c8f608437e9452fb5f99498aa31b1e3660df6519efbb8b90331699bbb0afe3d41dd120e8094f1093403e673b811eddb1ec6f8013f8d088cc42ebb1a90868a72b
|
data/Changelog.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# 3.7.1 (2026-11-29)
|
|
2
|
+
|
|
3
|
+
- Bound the total local header data read when loading the central directory.
|
|
4
|
+
- Tighten AES entry handling in `InputStream` and `DecryptedIo`.
|
|
5
|
+
- Bound Inflater memory use on highly compressible entries. [#681](https://github.com/rubyzip/rubyzip/pull/681)
|
|
6
|
+
|
|
7
|
+
Tooling/internal:
|
|
8
|
+
|
|
9
|
+
- Refine AGENTS.md.
|
|
10
|
+
|
|
1
11
|
# 3.7.0 (2026-09-18)
|
|
2
12
|
|
|
3
13
|
- Add AES Encryption. [#678](https://github.com/rubyzip/rubyzip/pull/678)
|
data/README.md
CHANGED
|
@@ -485,6 +485,16 @@ Prior to version 3.0, Zip64 support is disabled for writing by default.
|
|
|
485
485
|
|
|
486
486
|
_NOTE_: If Zip64 write support is enabled then any extractor subsequently used may also require Zip64 support to read from the resultant archive.
|
|
487
487
|
|
|
488
|
+
### Inflater chunk size
|
|
489
|
+
|
|
490
|
+
When reading a deflated entry, rubyzip feeds the compressed data to Zlib in chunks of 4 KiB. Deflate can compress data by up to around 1000:1, so this bounds how much is inflated beyond what a single read asked for (to about 4 MiB in the worst case). Smaller values lower that bound further, at the cost of a little more overhead per byte on entries that barely compress; larger values do the opposite. To change it:
|
|
491
|
+
|
|
492
|
+
```ruby
|
|
493
|
+
Zip.inflater_chunk_size = 1024 # Default is 4096.
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Consider setting `Zip.inflater_chunk_size` to a higher number (e.g. 32,768) if you know your data is not highly compressible (other zip files, JPEGs, etc) and you value performance over a smaller memory footprint.
|
|
497
|
+
|
|
488
498
|
### Block Form
|
|
489
499
|
|
|
490
500
|
You can set multiple settings at the same time by using a block:
|
|
@@ -183,6 +183,8 @@ module Zip
|
|
|
183
183
|
end
|
|
184
184
|
raise Error, 'Zip consistency problem while reading central directory entry' if eof || io.eof?
|
|
185
185
|
|
|
186
|
+
init_local_header_budget(io)
|
|
187
|
+
|
|
186
188
|
@entry_set = EntrySet.new
|
|
187
189
|
@size.times do
|
|
188
190
|
entry = Entry.read_c_dir_entry(io)
|
|
@@ -205,6 +207,24 @@ module Zip
|
|
|
205
207
|
end
|
|
206
208
|
end
|
|
207
209
|
|
|
210
|
+
# In a well-formed archive local headers do not overlap, so the total
|
|
211
|
+
# size of all of the local headers cannot be more than the size of the
|
|
212
|
+
# archive itself. Track this while reading local headers so that a small
|
|
213
|
+
# archive cannot cause the same data to be read and stored repeatedly.
|
|
214
|
+
def init_local_header_budget(io)
|
|
215
|
+
io_save = io.tell
|
|
216
|
+
io.seek(0, IO::SEEK_END)
|
|
217
|
+
@local_header_budget = io.tell
|
|
218
|
+
io.seek(io_save, IO::SEEK_SET)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def consume_local_header_budget(length)
|
|
222
|
+
@local_header_budget -= length
|
|
223
|
+
return unless @local_header_budget.negative?
|
|
224
|
+
|
|
225
|
+
raise Error, 'Zip consistency problem: local headers exceed archive size'
|
|
226
|
+
end
|
|
227
|
+
|
|
208
228
|
def read_local_extra_field(io)
|
|
209
229
|
buf = io.read(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH) || ''
|
|
210
230
|
return '' unless buf.bytesize == ::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH
|
|
@@ -212,6 +232,9 @@ module Zip
|
|
|
212
232
|
head, _, _, _, _, _, _, _, _, _, n_len, e_len = buf.unpack('VCCvvvvVVVvv')
|
|
213
233
|
return '' unless head == ::Zip::LOCAL_ENTRY_SIGNATURE
|
|
214
234
|
|
|
235
|
+
# Check before reading the extra field, so it is never allocated.
|
|
236
|
+
consume_local_header_budget(::Zip::LOCAL_ENTRY_STATIC_HEADER_LENGTH + n_len + e_len)
|
|
237
|
+
|
|
215
238
|
io.seek(n_len, IO::SEEK_CUR) # Skip over the entry name.
|
|
216
239
|
io.read(e_len)
|
|
217
240
|
end
|
|
@@ -15,7 +15,10 @@ module Zip
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def read(maxlen = nil)
|
|
18
|
-
|
|
18
|
+
if eof?
|
|
19
|
+
finish!
|
|
20
|
+
return (maxlen.nil? || maxlen.zero? ? '' : nil)
|
|
21
|
+
end
|
|
19
22
|
|
|
20
23
|
while maxlen.nil? || (@buffer.bytesize < maxlen)
|
|
21
24
|
break if input_finished?
|
|
@@ -23,14 +26,30 @@ module Zip
|
|
|
23
26
|
@buffer << produce_input
|
|
24
27
|
end
|
|
25
28
|
|
|
26
|
-
if input_finished?
|
|
27
|
-
@decrypter.check_integrity!(@io)
|
|
28
|
-
@integrity_verified = true
|
|
29
|
-
end
|
|
29
|
+
finish! if input_finished?
|
|
30
30
|
|
|
31
31
|
@buffer.slice!(0...(maxlen || @buffer.bytesize))
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# Consume any remaining encrypted data, without decrypting it for output,
|
|
35
|
+
# and then verify the integrity of the whole entry. This must be called
|
|
36
|
+
# once the consumer of this IO has decided that it has reached the end
|
|
37
|
+
# of the entry (e.g. a decompressor has seen the end of its stream),
|
|
38
|
+
# because that decision is based on data that is not covered by the
|
|
39
|
+
# integrity check.
|
|
40
|
+
#
|
|
41
|
+
# Note that, when streaming, data from earlier reads will already have
|
|
42
|
+
# been released before the integrity check is performed. Callers can
|
|
43
|
+
# only rely on the integrity of the data once the end of the entry has
|
|
44
|
+
# been reached without an error being raised.
|
|
45
|
+
def finish!
|
|
46
|
+
return if @integrity_verified
|
|
47
|
+
|
|
48
|
+
produce_input until input_finished?
|
|
49
|
+
@decrypter.check_integrity!(@io)
|
|
50
|
+
@integrity_verified = true
|
|
51
|
+
end
|
|
52
|
+
|
|
34
53
|
private
|
|
35
54
|
|
|
36
55
|
def eof?
|
|
@@ -45,8 +64,11 @@ module Zip
|
|
|
45
64
|
chunk_size = [@bytes_remaining, CHUNK_SIZE].min
|
|
46
65
|
return '' unless chunk_size.positive?
|
|
47
66
|
|
|
67
|
+
data = @io.read(chunk_size)
|
|
68
|
+
raise Error, 'Truncated encrypted entry data' if data.nil? || data.bytesize < chunk_size
|
|
69
|
+
|
|
48
70
|
@bytes_remaining -= chunk_size
|
|
49
|
-
@decrypter.decrypt(
|
|
71
|
+
@decrypter.decrypt(data)
|
|
50
72
|
end
|
|
51
73
|
end
|
|
52
74
|
end
|
data/lib/zip/inflater.rb
CHANGED
|
@@ -33,7 +33,7 @@ module Zip
|
|
|
33
33
|
def produce_input
|
|
34
34
|
retried = 0
|
|
35
35
|
begin
|
|
36
|
-
@zlib_inflater.inflate(input_stream.read(
|
|
36
|
+
@zlib_inflater.inflate(input_stream.read(Zip.inflater_chunk_size))
|
|
37
37
|
rescue Zlib::BufError
|
|
38
38
|
raise if retried >= 5 # how many times should we retry?
|
|
39
39
|
|
data/lib/zip/input_stream.rb
CHANGED
|
@@ -170,8 +170,9 @@ module Zip
|
|
|
170
170
|
io = if @current_entry.encrypted?
|
|
171
171
|
raise Error, 'A password is required to decode this zip file.' if @decrypter.nil?
|
|
172
172
|
|
|
173
|
-
get_decrypted_io
|
|
173
|
+
@decrypted_io = get_decrypted_io
|
|
174
174
|
else
|
|
175
|
+
@decrypted_io = nil
|
|
175
176
|
@archive_io
|
|
176
177
|
end
|
|
177
178
|
|
|
@@ -193,6 +194,7 @@ module Zip
|
|
|
193
194
|
if @decrypter.kind_of?(::Zip::AESDecrypter)
|
|
194
195
|
compressed_size -= @decrypter.header_bytesize
|
|
195
196
|
compressed_size -= ::Zip::AESEncryption::AUTHENTICATION_CODE_LENGTH
|
|
197
|
+
check_aes_sizes(compressed_size)
|
|
196
198
|
end
|
|
197
199
|
|
|
198
200
|
::Zip::DecryptedIo.new(@archive_io, @decrypter, compressed_size)
|
|
@@ -201,14 +203,6 @@ module Zip
|
|
|
201
203
|
def get_decompressor(io) # :nodoc:
|
|
202
204
|
return ::Zip::NullDecompressor if @current_entry.nil?
|
|
203
205
|
|
|
204
|
-
decompressed_size =
|
|
205
|
-
if @current_entry.incomplete? && @current_entry.crc == 0 &&
|
|
206
|
-
@current_entry.size == 0 && @complete_entry
|
|
207
|
-
@complete_entry.size
|
|
208
|
-
else
|
|
209
|
-
@current_entry.size
|
|
210
|
-
end
|
|
211
|
-
|
|
212
206
|
decompressor_class = ::Zip::Decompressor.find_by_compression_method(
|
|
213
207
|
@current_entry.compression_method
|
|
214
208
|
)
|
|
@@ -219,13 +213,46 @@ module Zip
|
|
|
219
213
|
decompressor_class.new(io, decompressed_size)
|
|
220
214
|
end
|
|
221
215
|
|
|
216
|
+
def decompressed_size # :nodoc:
|
|
217
|
+
if @current_entry.incomplete? && @current_entry.crc == 0 &&
|
|
218
|
+
@current_entry.size == 0 && @complete_entry
|
|
219
|
+
@complete_entry.size
|
|
220
|
+
else
|
|
221
|
+
@current_entry.size
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
222
225
|
def produce_input(maxlen = CHUNK_SIZE) # :nodoc:
|
|
223
|
-
@decompressor.read(maxlen)
|
|
226
|
+
output = @decompressor.read(maxlen)
|
|
227
|
+
verify_entry_integrity
|
|
228
|
+
output
|
|
224
229
|
end
|
|
225
230
|
|
|
226
231
|
def input_finished? # :nodoc:
|
|
232
|
+
verify_entry_integrity
|
|
227
233
|
@decompressor.eof?
|
|
228
234
|
end
|
|
235
|
+
|
|
236
|
+
private
|
|
237
|
+
|
|
238
|
+
# The sizes in the entry headers are not covered by the AES
|
|
239
|
+
# authentication code, so make sure that they are consistent with each
|
|
240
|
+
# other before trusting them.
|
|
241
|
+
def check_aes_sizes(payload_size)
|
|
242
|
+
raise Error, 'Invalid AES encrypted entry size' if payload_size.negative?
|
|
243
|
+
return unless @current_entry.compression_method == ::Zip::COMPRESSION_METHOD_STORE
|
|
244
|
+
|
|
245
|
+
# Stored data is the same size as its encrypted form.
|
|
246
|
+
raise Error, 'Invalid AES encrypted entry size' if payload_size != decompressed_size
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# The decompressor decides when it has reached the end of an entry, based
|
|
250
|
+
# on data that is not covered by any integrity check, so once it has
|
|
251
|
+
# finished, make sure that all of the encrypted data has been consumed
|
|
252
|
+
# and verified.
|
|
253
|
+
def verify_entry_integrity
|
|
254
|
+
@decrypted_io.finish! if @decrypted_io && @decompressor.eof?
|
|
255
|
+
end
|
|
229
256
|
end
|
|
230
257
|
end
|
|
231
258
|
|
data/lib/zip/version.rb
CHANGED
data/lib/zip.rb
CHANGED
|
@@ -55,7 +55,8 @@ module Zip
|
|
|
55
55
|
:case_insensitive_match,
|
|
56
56
|
:force_entry_names_encoding,
|
|
57
57
|
:validate_entry_sizes,
|
|
58
|
-
:validate_declared_number_of_entries
|
|
58
|
+
:validate_declared_number_of_entries,
|
|
59
|
+
:inflater_chunk_size
|
|
59
60
|
|
|
60
61
|
DEFAULT_RESTORE_OPTIONS = {
|
|
61
62
|
restore_ownership: false,
|
|
@@ -80,6 +81,7 @@ module Zip
|
|
|
80
81
|
@force_entry_names_encoding = nil
|
|
81
82
|
@validate_entry_sizes = true
|
|
82
83
|
@validate_declared_number_of_entries = false # Set this to `true` in v4.0.0?
|
|
84
|
+
@inflater_chunk_size = 4096
|
|
83
85
|
end
|
|
84
86
|
|
|
85
87
|
# Set options for RubyZip in one block.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubyzip
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.7.
|
|
4
|
+
version: 3.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Haines
|
|
@@ -197,9 +197,9 @@ licenses:
|
|
|
197
197
|
- BSD-2-Clause
|
|
198
198
|
metadata:
|
|
199
199
|
bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
|
|
200
|
-
changelog_uri: https://github.com/rubyzip/rubyzip/blob/v3.7.
|
|
201
|
-
documentation_uri: https://www.rubydoc.info/gems/rubyzip/3.7.
|
|
202
|
-
source_code_uri: https://github.com/rubyzip/rubyzip/tree/v3.7.
|
|
200
|
+
changelog_uri: https://github.com/rubyzip/rubyzip/blob/v3.7.1/Changelog.md
|
|
201
|
+
documentation_uri: https://www.rubydoc.info/gems/rubyzip/3.7.1
|
|
202
|
+
source_code_uri: https://github.com/rubyzip/rubyzip/tree/v3.7.1
|
|
203
203
|
wiki_uri: https://github.com/rubyzip/rubyzip/wiki
|
|
204
204
|
rubygems_mfa_required: 'true'
|
|
205
205
|
rdoc_options: []
|