From c787d94852b7d3e90212e8f7b08ad6ab6279c74d Mon Sep 17 00:00:00 2001 From: Andrew Meyer Date: Tue, 3 Apr 2018 16:07:18 -0400 Subject: [PATCH] Handle stored files with general purpose bit 3 set Signed-off-by: Sam Coward --- lib/zip/entry.rb | 2 +- lib/zip/input_stream.rb | 8 ++++++-- test/data/gpbit3stored.zip | Bin 0 -> 132 bytes test/file_test.rb | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 test/data/gpbit3stored.zip diff --git a/lib/zip/entry.rb b/lib/zip/entry.rb index 791ab32a..4d8e1751 100644 --- a/lib/zip/entry.rb +++ b/lib/zip/entry.rb @@ -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 diff --git a/lib/zip/input_stream.rb b/lib/zip/input_stream.rb index 5a82f145..95fc3c16 100644 --- a/lib/zip/input_stream.rb +++ b/lib/zip/input_stream.rb @@ -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' @@ -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) diff --git a/test/data/gpbit3stored.zip b/test/data/gpbit3stored.zip new file mode 100644 index 0000000000000000000000000000000000000000..3c73eeb3bc4564638443ea75dcc6fcf46cc856bd GIT binary patch literal 132 zcmWIWW@Zs#;9y{22(4-M0a9?l4rHa}=j)YJlmIEN0B?4V6{$vbEI?rp4)A7V5@AMY fMV13;g@G-NAQsf10B=?{5SI}MO@Xu}h{FH?7~2w0 literal 0 HcmV?d00001 diff --git a/test/file_test.rb b/test/file_test.rb index 32e21e33..489c0798 100644 --- a/test/file_test.rb +++ b/test/file_test.rb @@ -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|