mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-34922: Fix integer overflow in the digest() and hexdigest() methods (GH-9751)
for the SHAKE algorithm in the hashlib module.
This commit is contained in:
parent
f1aa8aed4a
commit
9b8c2e7676
3 changed files with 20 additions and 0 deletions
|
@ -230,6 +230,19 @@ class HashLibTestCase(unittest.TestCase):
|
|||
self.assertIsInstance(h.digest(), bytes)
|
||||
self.assertEqual(hexstr(h.digest()), h.hexdigest())
|
||||
|
||||
def test_digest_length_overflow(self):
|
||||
# See issue #34922
|
||||
large_sizes = (2**29, 2**32-10, 2**32+10, 2**61, 2**64-10, 2**64+10)
|
||||
for cons in self.hash_constructors:
|
||||
h = cons()
|
||||
if h.name not in self.shakes:
|
||||
continue
|
||||
for digest in h.digest, h.hexdigest:
|
||||
self.assertRaises(ValueError, digest, -10)
|
||||
for length in large_sizes:
|
||||
with self.assertRaises((ValueError, OverflowError)):
|
||||
digest(length)
|
||||
|
||||
def test_name_attribute(self):
|
||||
for cons in self.hash_constructors:
|
||||
h = cons()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue