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

Entry#unpack_local_entry can't get compressed_size #525

Closed
blackerhand opened this issue Apr 25, 2022 · 4 comments
Closed

Entry#unpack_local_entry can't get compressed_size #525

blackerhand opened this issue Apr 25, 2022 · 4 comments

Comments

@blackerhand
Copy link

blackerhand commented Apr 25, 2022

First, I get a zip file use mac osx, (select 2 file, right-click, select compress).

Second, I use Zip::File open it, It's right. but Zip::InputStream is error(only get one entry).

Zip::File.open('2.zip') do |zip_file|
  zip_file.each do |entry|
    puts "Extracting #{entry.name}" 
    entry.compressed_size #  > 0 
  end
end

input = Zip::InputStream.open(::StringIO.new(io), 0, decrypter)
while entry = input.get_next_entry

entry.compressed_size  # = 0  
# I can't get the second file, because offset not right

Because the zip file has a password, I must use Zip::InputStream

ruby 2.6.6p146
rubyzip (2.3.2)

@blackerhand
Copy link
Author

blackerhand commented Apr 25, 2022

def get_next_entry
  @archive_io.seek(@current_entry.next_header_offset, IO::SEEK_SET) if @current_entry
  open_entry
end

def unpack_local_entry(buf)
      @header_signature,
        @version,
        @fstype,
        @gp_flags,
        @compression_method,
        @last_mod_time,
        @last_mod_date,
        @crc,
        @compressed_size, # 0
        @size,
        @name_length,
        @extra_length = buf.unpack('VCCvvvvVVVvv')
end 

https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html

@blackerhand
Copy link
Author

blackerhand commented Apr 26, 2022

Checkout rubyzip 3.0.0, I get error:

Zip::GPFBit3Error:
It is not possible to get complete info from the local header to extract this entry (GP flags bit 3 is set). Please use Zip::File instead of Zip::InputStream.

But Zip::File not supprot decrypter, It can be a constant cycle.

@blackerhand
Copy link
Author

@hainesr

@hainesr
Copy link
Member

hainesr commented Apr 27, 2022

This is partly an issue with zip archives created by Archive on OSX - there's a bit of an explanation here: #510 (comment)

We do need to enable reading/writing encrypted zips via Zip::File, which is noted as an issue here: #519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants