Skip to content

Commit

Permalink
Read EOCD record for Zip64 files.
Browse files Browse the repository at this point in the history
Means we actually read in the file-level comment now!

Fixes rubyzip#492.
  • Loading branch information
hainesr committed Jun 11, 2021
1 parent be1c5b7 commit 7df623f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/zip/central_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,21 @@ def unpack_e_o_c_d(buffer) #:nodoc:
buf = buffer.slice(index, buffer.size)

_, # END_OF_CDS signature. We know we have this at this point.
@number_of_this_disk,
@number_of_disk_with_start_of_cdir,
@total_number_of_entries_in_cdir_on_this_disk,
@size,
@size_in_bytes,
@cdir_offset,
num_disk,
num_disk_cdir,
num_cdir_disk,
num_entries,
size_in_bytes,
cdir_offset,
comment_length = buf.unpack('VvvvvVVv')

@number_of_this_disk = num_disk unless num_disk == 0xFFFF
@number_of_disk_with_start_of_cdir = num_disk_cdir unless num_disk_cdir == 0xFFFF
@total_number_of_entries_in_cdir_on_this_disk = num_cdir_disk unless num_cdir_disk == 0xFFFF
@size = num_entries unless num_entries == 0xFFFF
@size_in_bytes = size_in_bytes unless size_in_bytes == 0xFFFFFFFF
@cdir_offset = cdir_offset unless cdir_offset == 0xFFFFFFFF

@comment = if comment_length.positive?
buf.slice(STATIC_EOCD_SIZE, comment_length)
else
Expand Down Expand Up @@ -182,11 +189,8 @@ def read_local_extra_field(io)

def read_from_stream(io) #:nodoc:
buf = start_buf(io)
if zip64_file?(buf)
unpack_64_e_o_c_d(buf)
else
unpack_e_o_c_d(buf)
end
unpack_64_e_o_c_d(buf) if zip64_file?(buf)
unpack_e_o_c_d(buf)
read_central_directory_entries(io)
end

Expand Down
4 changes: 4 additions & 0 deletions test/zip64_full_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ def test_large_zip_file
::Zip.write_zip64_support = true
first_text = 'starting out small'
last_text = 'this tests files starting after 4GB in the archive'
comment_text = 'this is a file comment in a zip64 archive'

::Zip::File.open(HUGE_ZIP, ::Zip::File::CREATE) do |zf|
zf.comment = comment_text

zf.get_output_stream('first_file.txt') do |io|
io.write(first_text)
end
Expand All @@ -44,6 +47,7 @@ def test_large_zip_file
)
assert_equal(first_text, zf.read('first_file.txt'))
assert_equal(last_text, zf.read('last_file.txt'))
assert_equal(comment_text, zf.comment)
end

# NOTE: if this fails, be sure you have UnZip version 6.0 or newer
Expand Down

0 comments on commit 7df623f

Please sign in to comment.