Commit 1bf687b
Fix Digest::SHA1#update with large input
Digest::SHA1#update fails when a very large String is passed in a
single call.
Passing 2**29 bytes (512 MB) or more at once does not update the
message length counter correctly, which results in producing an
incorrect output.
$ ruby -rdigest -e'd=Digest::SHA1.new; d<<"a"*(512*1024*1024); puts d.hexdigest'
40cd9c4b14e7b8d0940a3a92c8a7661fad85a821
$ ruby -rdigest -e'd=Digest::SHA1.new; 512.times{d<<"a"*(1024*1024)}; puts d.hexdigest'
0ea59bfe8787939816796610c73deb1c625e03ed
$ ruby -e'print "a"*(512*1024*1024)'|sha1sum
0ea59bfe8787939816796610c73deb1c625e03ed -
Passing 2**32 bytes or more causes an infinite loop because the loop
counter is too small.
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>1 parent 5f17e37 commit 1bf687b
1 file changed
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
| 224 | + | |
224 | 225 | | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
229 | 230 | | |
230 | | - | |
| 231 | + | |
| 232 | + | |
231 | 233 | | |
232 | 234 | | |
233 | 235 | | |
| |||
0 commit comments