Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Thu, 01 Dec 2011 23:26:37
Message-Id: e7a0179ed39f707a42b8c15157bdb3f0aa45dd13.zmedico@gentoo
1 commit: e7a0179ed39f707a42b8c15157bdb3f0aa45dd13
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Thu Dec 1 23:25:31 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Thu Dec 1 23:25:31 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=e7a0179e
7
8 checksum.py: detect PyPy crashes in hashlib
9
10 Use a fork to try and PyPy by digesting random data with hashlib
11 functions. It doesn't look like a bug has been reported upstream for
12 this yet, so it may or may not be reproducible by others. Anyway, this
13 allows me to avoid crashing the main PyPy process until I find a real
14 fix.
15
16 ---
17 pym/portage/checksum.py | 29 +++++++++++++++++++++++++++++
18 1 files changed, 29 insertions(+), 0 deletions(-)
19
20 diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
21 index f10fc4d..77035b6 100644
22 --- a/pym/portage/checksum.py
23 +++ b/pym/portage/checksum.py
24 @@ -9,6 +9,7 @@ from portage import os
25 from portage import _encodings
26 from portage import _unicode_encode
27 import errno
28 +import platform
29 import stat
30 import tempfile
31
32 @@ -61,6 +62,28 @@ class _generate_hash_function(object):
33
34 return (checksum.hexdigest(), size)
35
36 +_test_hash_func = False
37 +if platform.python_implementation() == 'PyPy':
38 + def _test_hash_func(constructor):
39 + """
40 + Test for PyPy crashes observed with hashlib's ripemd160 and whirlpool
41 + functions executed under pypy-1.7 with Python 2.7.1:
42 + *** glibc detected *** pypy-c1.7: free(): invalid next size (fast): 0x0b963a38 ***
43 + *** glibc detected *** pypy-c1.7: free(): corrupted unsorted chunks: 0x09c490b0 ***
44 + """
45 + import random
46 + pid = os.fork()
47 + if pid == 0:
48 + data = list(b'abcdefg')
49 + for i in range(10):
50 + checksum = constructor()
51 + random.shuffle(data)
52 + checksum.update(b''.join(data))
53 + checksum.hexdigest()
54 + os._exit(os.EX_OK)
55 + pid, status = os.waitpid(pid, 0)
56 + return os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK
57 +
58 # Define hash functions, try to use the best module available. Later definitions
59 # override earlier ones
60
61 @@ -129,6 +152,12 @@ try:
62 except ValueError:
63 pass
64 else:
65 + if _test_hash_func and \
66 + not _test_hash_func(functools.partial(hashlib.new, hash_name)):
67 + portage.util.writemsg("\n!!! hash function appears to "
68 + "crash python: %s from %s\n" %
69 + (hash_name, "hashlib"), noiselevel=-1)
70 + continue
71 globals()['%shash' % local_name] = \
72 _generate_hash_function(local_name.upper(), \
73 functools.partial(hashlib.new, hash_name), \