UniversalTime: correctly parse included timestamps.

From the documentation: "...times that are present will appear in the
order indicated, but any combination of times may be omitted. (Creation
time may be present without access time, for example.)"

This fixes the parsing so that the times are read into the correct
fields, according to the flags. Before they were simply assumed to be in
order and all present.
This commit is contained in:
Robert Haines 2019-10-27 18:56:40 +00:00
parent a5e785c737
commit 9849500d73
1 changed files with 9 additions and 4 deletions

View File

@ -39,10 +39,15 @@ module Zip
size, content = initial_parse(binstr)
return if !size || size <= 0
@flag, mt, at, ct = content.unpack('Cl<l<l<')
mt && @mtime ||= ::Zip::DOSTime.at(mt)
at && @atime ||= ::Zip::DOSTime.at(at)
ct && @ctime ||= ::Zip::DOSTime.at(ct)
@flag, *times = content.unpack('Cl<l<l<')
# Parse the timestamps, in order, based on which flags are set.
return if times[0].nil?
@mtime ||= ::Zip::DOSTime.at(times.shift) unless @flag & MTIME_MASK == 0
return if times[0].nil?
@atime ||= ::Zip::DOSTime.at(times.shift) unless @flag & ATIME_MASK == 0
return if times[0].nil?
@ctime ||= ::Zip::DOSTime.at(times.shift) unless @flag & CTIME_MASK == 0
end
def ==(other)