Skip to content

Commit

Permalink
UniversalTime: correctly parse included timestamps.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hainesr committed Dec 15, 2019
1 parent a5e785c commit 9849500
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/zip/extra_field/universal_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def merge(binstr)
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)
Expand Down

0 comments on commit 9849500

Please sign in to comment.