Skip to content

Commit

Permalink
Merge pull request #358 from idoru/handle-gpbit-3
Browse files Browse the repository at this point in the history
Handle stored files with general purpose bit 3 set
  • Loading branch information
simonoff committed Apr 23, 2018
2 parents 05af123 + c787d94 commit f073f64
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
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

0 comments on commit f073f64

Please sign in to comment.