8000 Detect and raise GPFBit3Error in `InputStream.get_next_entry`. · rubyzip/rubyzip@19e5f4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 19e5f4a

Browse files
committed
Detect and raise GPFBit3Error in InputStream.get_next_entry.
We were previously trying to work out where the next entry would be, even with GP bit 3 set, but the logic was flaky and cannot really be correct given the data available. It's not expected behaviour, so raise the error instead. This means that we get rid of the incorrect `Entry.data_descriptor_size` which was doing more harm than good.
1 parent 8071290 commit 19e5f4a

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

lib/zip/entry.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def cdir_header_size #:nodoc:all
215215
end
216216

217217
def next_header_offset #:nodoc:all
218-
local_entry_offset + compressed_size + data_descripto 8000 r_size
218+
local_entry_offset + compressed_size
219219
end
220220

221221
# Extracts entry to file dest_path (defaults to @name).
@@ -723,10 +723,6 @@ def parse_zip64_extra(for_local_header) #:nodoc:all
723723
end
724724
end
725725

726-
def data_descriptor_size
727-
(@gp_flags & 0x0008) > 0 ? 16 : 0
728-
end
729-
730726
# For DEFLATED compression *only*: set the general purpose flags 1 and 2 to
731727
# indicate compression level. This seems to be mainly cosmetic but they are
732728
# generally set by other tools - including in docx files. It is these flags

lib/zip/input_stream.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,17 @@ def close
6969
# the first entry in the archive. Returns nil when there are
7070
# no more entries.
7171
def get_next_entry
72-
@archive_io.seek(@current_entry.next_header_offset, IO::SEEK_SET) if @current_entry
72+
unless @current_entry.nil?
73+
if @current_entry.incomplete?
74+
raise GPFBit3Error,
75+
'It is not possible to get complete info from the local ' \
76+
'header to extract this entry (GP flags bit 3 is set). ' \
77+
'Please use `Zip::File` instead of `Zip::InputStream`.'
78+
end
79+
80+
@archive_io.seek(@current_entry.next_header_offset, IO::SEEK_SET)
81+
end
82+
7383
open_entry
7484
end
7585

test/data/gpbit3stored.zip

9.25 KB
Binary file not shown.

test/file_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ def test_create_from_scratch
4545

4646
def test_get_input_stream_stored_with_gpflag_bit3
4747
::Zip::File.open('test/data/gpbit3stored.zip') do |zf|
48-
assert_equal("foo\n", zf.read('foo.txt'))
48+
zis = zf.get_input_stream('file1.txt')
49+
assert_raises(::Zip::GPFBit3Error) do
50+
zis.get_next_entry
51+
end
52+
zf.get_input_stream('file2.txt')
4953
end
5054
end
5155

0 commit comments

Comments
 (0)
0