8000 Handle stored files with general purpose bit 3 set · rubyzip/rubyzip@c787d94 · GitHub
[go: up one dir, main page]

Skip to content

Commit c787d94

Browse files
ameyer-pivotalidoru
authored andcommitted
Handle stored files with general purpose bit 3 set
Signed-off-by: Sam Coward <scoward@pivotal.io>
1 parent 05af123 commit c787d94

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lib/zip/entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def get_input_stream(&block)
500500
end
501501
else
502502
zis = ::Zip::InputStream.new(@zipfile, local_header_offset)
503-
zis.instance_variable_set(:@internal, true)
503+
zis.instance_variable_set(:@complete_entry, self)
504504
zis.get_next_entry
505505
if block_given?
506506
begin

lib/zip/input_stream.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def open_entry
129129
end
130130
if @current_entry && @current_entry.gp_flags & 8 == 8 && @current_entry.crc == 0 \
131131
&& @current_entry.compressed_size == 0 \
132-
&& @current_entry.size == 0 && !@internal
132+
&& @current_entry.size == 0 && !@complete_entry
133133
raise GPFBit3Error,
134134
'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \
135135
'Please use ::Zip::File instead of ::Zip::InputStream'
@@ -143,7 +143,11 @@ def get_decompressor
143143
if @current_entry.nil?
144144
::Zip::NullDecompressor
145145
elsif @current_entry.compression_method == ::Zip::Entry::STORED
146-
::Zip::PassThruDecompressor.new(@archive_io, @current_entry.size)
146+
if @current_entry.gp_flags & 8 == 8 && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry
147+
::Zip::PassThruDecompressor.new(@archive_io, @complete_entry.size)
148+
else
149+
::Zip::PassThruDecompressor.new(@archive_io, @current_entry.size)
150+
end
147151
elsif @current_entry.compression_method == ::Zip::Entry::DEFLATED
148152
header = @archive_io.read(@decrypter.header_bytesize)
149153
@decrypter.reset!(header)

test/data/gpbit3stored.zip

132 Bytes
Binary file not shown.

test/file_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def test_create_from_scratch_with_old_create_parameter
5555
assert_equal(2, zfRead.entries.length)
5656
end
5757

58+
def test_get_input_stream_stored_with_gpflag_bit3
59+
::Zip::File.open('test/data/gpbit3stored.zip') do |zf|
60+
assert_equal("foo\n", zf.read("foo.txt"))
61+
end
62+
end
63+
5864
def test_get_output_stream
5965
entryCount = nil
6066
::Zip::File.open(TEST_ZIP.zip_name) do |zf|

0 commit comments

Comments
 (0)
0