Fix reading zip files with max length file comment.

If a zip file has a comment that is 65,535 characters long - which is a
valid length and the maximum allowable length - the initial read of the
archive fails to find the End of Central Directory Record and therefore
cannot read the rest of the file.

This commit fixes this by making sure that we look far enough back into
the file from the end to find the EoCDR. Test added to catch
regressions.

Fixes #508.
This commit is contained in:
Robert Haines 2021-11-19 19:35:36 +00:00
parent bc6523ec43
commit f7cd692e15
3 changed files with 6 additions and 1 deletions

View File

@ -7,9 +7,9 @@ module Zip
END_OF_CDS = 0x06054b50
ZIP64_END_OF_CDS = 0x06064b50
ZIP64_EOCD_LOCATOR = 0x07064b50
MAX_END_OF_CDS_SIZE = 65_536 + 18
STATIC_EOCD_SIZE = 22
ZIP64_STATIC_EOCD_SIZE = 56
MAX_END_OF_CDS_SIZE = 65_535 + STATIC_EOCD_SIZE
attr_reader :comment

Binary file not shown.

View File

@ -181,6 +181,11 @@ class ZipFileTest < MiniTest::Test
assert zf.entries.map(&:name).include?('zippedruby1.rb')
end
def test_open_file_with_max_length_comment
# Should not raise any errors.
Zip::File.open('test/data/max_length_file_comment.zip')
end
def test_cleans_up_tempfiles_after_close
zf = ::Zip::File.new(EMPTY_FILENAME, create: true)
zf.get_output_stream('myFile') do |os|