Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle stored files with general purpose bit 3 set #358

Merged
merged 1 commit into from Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/zip/entry.rb
Expand Up @@ -500,7 +500,7 @@ def get_input_stream(&block)
end
else
zis = ::Zip::InputStream.new(@zipfile, local_header_offset)
zis.instance_variable_set(:@internal, true)
zis.instance_variable_set(:@complete_entry, self)
zis.get_next_entry
if block_given?
begin
Expand Down
8 changes: 6 additions & 2 deletions lib/zip/input_stream.rb
Expand Up @@ -129,7 +129,7 @@ def open_entry
end
if @current_entry && @current_entry.gp_flags & 8 == 8 && @current_entry.crc == 0 \
&& @current_entry.compressed_size == 0 \
&& @current_entry.size == 0 && !@internal
&& @current_entry.size == 0 && !@complete_entry
raise GPFBit3Error,
'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \
'Please use ::Zip::File instead of ::Zip::InputStream'
Expand All @@ -143,7 +143,11 @@ def get_decompressor
if @current_entry.nil?
::Zip::NullDecompressor
elsif @current_entry.compression_method == ::Zip::Entry::STORED
::Zip::PassThruDecompressor.new(@archive_io, @current_entry.size)
if @current_entry.gp_flags & 8 == 8 && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry
::Zip::PassThruDecompressor.new(@archive_io, @complete_entry.size)
else
::Zip::PassThruDecompressor.new(@archive_io, @current_entry.size)
end
elsif @current_entry.compression_method == ::Zip::Entry::DEFLATED
header = @archive_io.read(@decrypter.header_bytesize)
@decrypter.reset!(header)
Expand Down
Binary file added test/data/gpbit3stored.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions test/file_test.rb
Expand Up @@ -55,6 +55,12 @@ def test_create_from_scratch_with_old_create_parameter
assert_equal(2, zfRead.entries.length)
end

def test_get_input_stream_stored_with_gpflag_bit3
::Zip::File.open('test/data/gpbit3stored.zip') do |zf|
assert_equal("foo\n", zf.read("foo.txt"))
end
end

def test_get_output_stream
entryCount = nil
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
Expand Down