lib/zip/zip_central_directory.rb in rubyzip-0.9.8 vs lib/zip/zip_central_directory.rb in rubyzip-0.9.9

- old
+ new

@@ -58,11 +58,15 @@ @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) + if commentLength <= 0 + @comment = buf.slice!(0, buf.size) + else + @comment = buf.read(commentLength) + end raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0 end def read_central_directory_entries(io) #:nodoc: begin @@ -85,28 +89,14 @@ def get_e_o_c_d(io) #:nodoc: begin io.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END) rescue Errno::EINVAL io.seek(0, IO::SEEK_SET) - rescue Errno::EFBIG # FreeBSD 4.9 raise Errno::EFBIG instead of Errno::EINVAL - io.seek(0, IO::SEEK_SET) end - - # 'buf = io.read' substituted with lump of code to work around FreeBSD 4.5 issue - retried = false - buf = nil - begin - buf = io.read - rescue Errno::EFBIG # FreeBSD 4.5 may raise Errno::EFBIG - raise if (retried) - retried = true - io.seek(0, IO::SEEK_SET) - retry - end - + buf = io.read sigIndex = buf.rindex([END_OF_CENTRAL_DIRECTORY_SIGNATURE].pack('V')) raise ZipError, "Zip end of central directory signature not found" unless sigIndex - buf = buf.slice!((sigIndex + 4)...(buf.bytesize)) + buf = buf.slice!((sigIndex + 4)..(buf.bytesize)) def buf.read(count) slice!(0, count) end