#11 rubyzip cannot read central directory of some zip archives

open
None
7
2014-10-21
2006-07-29
No

I've received the following bug report by email:

Hi, Thomas. I understand you are the maintainer of
the rubyzip library.
I've found a problem with decompressing some zip
files, returning:

c:/ruby/lib/ruby/gems/1.8/gems/rubyzip-
0.9.1/lib/zip/zip.rb:1213:in
`read_e_o_c_d': Zip consistency problem while reading
eocd structure
(Zip::ZipError)

The zip files in question are those of the ruby quiz
solutions.
Attached is a simple program to retrieve rubyquizzes
and decompress
their solutions from the net that exhibits the
behavior.
Just run it like:

download_quizzes.rb 1 1

For the record, the same zip file decompresses
properly using the
stand-alone gnu unzip utility.

PS. This is on windows, btw, using the latest
version of the rubyzip
gem on Ruby's One-Click Installer.

Discussion

  • Logged In: YES
    user_id=1222

    I've investigated and it turns out that there is an extra
    byte at the end of the file that rubyzip cannot account
    for and therefore it throws an exception to flag the
    problem. If I truncate the file to get rid of the last
    byte rubyzip can handle the file. zipinfo verifies the
    archive as valid, so we should be able to read it.

    A further note: info-zip's unzip and zipinfo doesn't even
    blink if you append a bunch of garbage to the end of a zip
    archive. Should rubyzip be as forgiving?

     
  • Chris
    Chris
    2010-06-08

    I'm seeing this as well.

    i threw in a ruby-debug call in read_e_o_c_d:

    def read_e_o_c_d(io) #:nodoc:
    buf = get_e_o_c_d(io)
    debugger
    @numberOfThisDisk = ZipEntry::read_zip_short(buf)
    @numberOfDiskWithStartOfCDir = ZipEntry::read_zip_short(buf)
    @totalNumberOfEntriesInCDirOnThisDisk = ZipEntry::read_zip_short(buf)
    @size = ZipEntry::read_zip_short(buf)
    @sizeInBytes = ZipEntry::read_zip_long(buf)
    @cdirOffset = ZipEntry::read_zip_long(buf)
    commentLength = ZipEntry::read_zip_short(buf)
    @comment = buf.read(commentLength)
    debugger
    raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0
    end

    irb:

    require 'zip/zip'
    => true
    require 'ruby-debug'
    => true
    z = Zip::ZipFile.open('1522.zip')
    /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1237
    @numberOfThisDisk = ZipEntry::read_zip_short(buf)
    (rdb:1) pp buf
    "\000\000\000\000\v\000\v\000\212\002\000\000j\003\001\000\000\000\000\000\000"
    (rdb:1) cont
    /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1246
    raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0
    (rdb:1) pp buf
    "\000\000\000"
    (rdb:1) cont
    Zip::ZipError: Zip consistency problem while reading eocd structure
    from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1246:in read_e_o_c_d' from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1262:inread_from_stream'
    from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1394:in initialize' from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1394:inopen'
    from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1394:in initialize' from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1412:innew'
    from /usr/local/lib/ruby/gems/1.8/gems/rubyzip-0.9.4/lib/zip/zip.rb:1412:in `open'
    from (irb):3

     


Anonymous


Cancel   Add attachments