summaryrefslogtreecommitdiffstats
path: root/pym/portage/checksum.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-12-01 15:25:31 -0800
committerZac Medico <zmedico@gentoo.org>2011-12-01 15:25:31 -0800
commite7a0179ed39f707a42b8c15157bdb3f0aa45dd13 (patch)
tree7873135cdac75458b769904d8451de5b3c5e3a53 /pym/portage/checksum.py
parentb432a1b3051d91546649e8f3190675767461d8e8 (diff)
downloadportage-e7a0179ed39f707a42b8c15157bdb3f0aa45dd13.tar.gz
portage-e7a0179ed39f707a42b8c15157bdb3f0aa45dd13.tar.bz2
portage-e7a0179ed39f707a42b8c15157bdb3f0aa45dd13.zip
checksum.py: detect PyPy crashes in hashlib
Use a fork to try and PyPy by digesting random data with hashlib functions. It doesn't look like a bug has been reported upstream for this yet, so it may or may not be reproducible by others. Anyway, this allows me to avoid crashing the main PyPy process until I find a real fix.
Diffstat (limited to 'pym/portage/checksum.py')
-rw-r--r--pym/portage/checksum.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index f10fc4d55..77035b600 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -9,6 +9,7 @@ from portage import os
from portage import _encodings
from portage import _unicode_encode
import errno
+import platform
import stat
import tempfile
@@ -61,6 +62,28 @@ class _generate_hash_function(object):
return (checksum.hexdigest(), size)
+_test_hash_func = False
+if platform.python_implementation() == 'PyPy':
+ def _test_hash_func(constructor):
+ """
+ Test for PyPy crashes observed with hashlib's ripemd160 and whirlpool
+ functions executed under pypy-1.7 with Python 2.7.1:
+ *** glibc detected *** pypy-c1.7: free(): invalid next size (fast): 0x0b963a38 ***
+ *** glibc detected *** pypy-c1.7: free(): corrupted unsorted chunks: 0x09c490b0 ***
+ """
+ import random
+ pid = os.fork()
+ if pid == 0:
+ data = list(b'abcdefg')
+ for i in range(10):
+ checksum = constructor()
+ random.shuffle(data)
+ checksum.update(b''.join(data))
+ checksum.hexdigest()
+ os._exit(os.EX_OK)
+ pid, status = os.waitpid(pid, 0)
+ return os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK
+
# Define hash functions, try to use the best module available. Later definitions
# override earlier ones
@@ -129,6 +152,12 @@ try:
except ValueError:
pass
else:
+ if _test_hash_func and \
+ not _test_hash_func(functools.partial(hashlib.new, hash_name)):
+ portage.util.writemsg("\n!!! hash function appears to "
+ "crash python: %s from %s\n" %
+ (hash_name, "hashlib"), noiselevel=-1)
+ continue
globals()['%shash' % local_name] = \
_generate_hash_function(local_name.upper(), \
functools.partial(hashlib.new, hash_name), \