Skip to content

Commit

Permalink
UniversalTime: correctly pack/unpack the timestamps.
Browse files Browse the repository at this point in the history
From the documentation: "The time values are in standard Unix signed-long
format, indicating the number of seconds since 1 January 1970 00:00:00."

The three time values were being unpacked with 'VVV', which is unsigned
32-bit, but they should be unpacked with 'l<l<l<': signed-long little
endian.
  • Loading branch information
hainesr committed Dec 15, 2019
1 parent b58b97f commit 65cfd8a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/zip/extra_field/universal_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def merge(binstr)
return if binstr.empty?
size, content = initial_parse(binstr)
size || return
@flag, mt, at, ct = content.unpack('CVVV')
@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)
Expand All @@ -51,15 +51,15 @@ def ==(other)

def pack_for_local
s = [@flag].pack('C')
@flag & 1 != 0 && s << [@mtime.to_i].pack('V')
@flag & 2 != 0 && s << [@atime.to_i].pack('V')
@flag & 4 != 0 && s << [@ctime.to_i].pack('V')
@flag & 1 != 0 && s << [@mtime.to_i].pack('l<')
@flag & 2 != 0 && s << [@atime.to_i].pack('l<')
@flag & 4 != 0 && s << [@ctime.to_i].pack('l<')
s
end

def pack_for_c_dir
s = [@flag].pack('C')
@flag & 1 == 1 && s << [@mtime.to_i].pack('V')
@flag & 1 == 1 && s << [@mtime.to_i].pack('l<')
s
end
end
Expand Down

0 comments on commit 65cfd8a

Please sign in to comment.