summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2021-10-25 17:02:42 +0200
committergit <svn-admin@ruby-lang.org>2021-10-26 01:51:05 +0900
commit557fa389155810f38f111c00a649c313a639dbb5 (patch)
treee3bddf2cdef57ae6721786a810500691ff8bb5fc
parent244c98e635a01cc7cfde9e24ed4b44413e6c3e75 (diff)
downloadruby-557fa389155810f38f111c00a649c313a639dbb5.tar.gz
[rubygems/rubygems] Fix Bundler::Digest#sha1 on big-endian systems
As noticed by @nobu https://github.com/rubygems/rubygems/pull/4989#discussion_r735674633 From wikipedia: https://en.wikipedia.org/wiki/SHA-1#SHA-1_pseudocode > append ml, the original message length in bits, as a 64-bit big-endian integer. `Q` is native endian, so little-endian on most modern hardware. The original code from RubyDigest reverses the bytes: https://github.com/Solistra/ruby-digest/blob/d15f906caf09171f897efc74645c9e31373d7fd1/lib/ruby_digest.rb#L521 But that makes the code non-portable, the correct way is to directly ask for a big-endian representation. https://github.com/rubygems/rubygems/commit/ba2be01ea4
-rw-r--r--lib/bundler/digest.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/bundler/digest.rb b/lib/bundler/digest.rb
index d560b82439..759f609416 100644
--- a/lib/bundler/digest.rb
+++ b/lib/bundler/digest.rb
@@ -59,7 +59,7 @@ module Bundler
size = string.bytesize * 8
buffer = string.bytes << 128
buffer << 0 while buffer.size % 64 != 56
- [size].pack("Q").bytes.reverse_each {|b| buffer << b }
+ buffer.concat([size].pack("Q>").bytes)
buffer.each_slice(64, &block)
end