summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_hashlib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-10-11 04:41:00 (GMT)
committerGitHub <noreply@github.com>2018-10-11 04:41:00 (GMT)
commit9b8c2e767643256202bb11456ba8665593b9a500 (patch)
tree92b674df44b5bb6d14583e910cf38f0ead9837bb /Lib/test/test_hashlib.py
parentf1aa8aed4a8ce9753ffa8713e7d3461663e0624d (diff)
downloadcpython-9b8c2e767643256202bb11456ba8665593b9a500.zip
cpython-9b8c2e767643256202bb11456ba8665593b9a500.tar.gz
cpython-9b8c2e767643256202bb11456ba8665593b9a500.tar.bz2
bpo-34922: Fix integer overflow in the digest() and hexdigest() methods (GH-9751)
for the SHAKE algorithm in the hashlib module.
Diffstat (limited to 'Lib/test/test_hashlib.py')
-rw-r--r--Lib/test/test_hashlib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index c8a873f..f83f73a 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -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()