Warn when an entry size is invalid

This commit is contained in:
John Lees-Miller 2019-09-18 18:34:23 +01:00
parent 7849f7362a
commit 97cb6aefe6
1 changed files with 9 additions and 4 deletions

View File

@ -604,14 +604,19 @@ module Zip
set_extra_attributes_on_path(dest_path) set_extra_attributes_on_path(dest_path)
bytes_written = 0 bytes_written = 0
warned = false
buf = ''.dup buf = ''.dup
while (buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf)) while (buf = is.sysread(::Zip::Decompressor::CHUNK_SIZE, buf))
os << buf os << buf
next unless ::Zip.validate_entry_sizes
bytes_written += buf.bytesize bytes_written += buf.bytesize
if bytes_written > size if bytes_written > size && !warned
raise ::Zip::EntrySizeError, "Entry #{name} should be #{size}B but is larger when inflated" message = "Entry #{name} should be #{size}B but is larger when inflated"
if ::Zip.validate_entry_sizes
raise ::Zip::EntrySizeError, message
else
puts "WARNING: #{message}"
warned = true
end
end end
end end
end end