Line 0
Link Here
|
|
|
1 |
|
2 |
|
3 |
Patch for CVE-2008-2315 taken from Gentoo. |
4 |
|
5 |
--- Lib/test/test_bigmem.py.orig 2007-11-30 21:53:17.000000000 +0000 |
6 |
+++ Lib/test/test_bigmem.py 2008-08-30 10:16:13.000000000 +0100 |
7 |
@@ -1,5 +1,5 @@ |
8 |
from test import test_support |
9 |
-from test.test_support import bigmemtest, _1G, _2G |
10 |
+from test.test_support import bigmemtest, _1G, _2G, _4G, precisionbigmemtest |
11 |
|
12 |
import unittest |
13 |
import operator |
14 |
@@ -54,6 +54,22 @@ |
15 |
self.assertEquals(s[lpadsize:-rpadsize], SUBSTR) |
16 |
self.assertEquals(s.strip(), SUBSTR.strip()) |
17 |
|
18 |
+ @precisionbigmemtest(size=_2G - 1, memuse=1) |
19 |
+ def test_center_unicode(self, size): |
20 |
+ SUBSTR = u' abc def ghi' |
21 |
+ try: |
22 |
+ s = SUBSTR.center(size) |
23 |
+ except OverflowError: |
24 |
+ pass # acceptable on 32-bit |
25 |
+ else: |
26 |
+ self.assertEquals(len(s), size) |
27 |
+ lpadsize = rpadsize = (len(s) - len(SUBSTR)) // 2 |
28 |
+ if len(s) % 2: |
29 |
+ lpadsize += 1 |
30 |
+ self.assertEquals(s[lpadsize:-rpadsize], SUBSTR) |
31 |
+ self.assertEquals(s.strip(), SUBSTR.strip()) |
32 |
+ del s |
33 |
+ |
34 |
@bigmemtest(minsize=_2G, memuse=2) |
35 |
def test_count(self, size): |
36 |
SUBSTR = ' abc def ghi' |
37 |
@@ -70,10 +86,44 @@ |
38 |
s = '.' * size |
39 |
self.assertEquals(len(s.decode('utf-8')), size) |
40 |
|
41 |
+ def basic_encode_test(self, size, enc, c=u'.', expectedsize=None): |
42 |
+ if expectedsize is None: |
43 |
+ expectedsize = size |
44 |
+ |
45 |
+ s = c * size |
46 |
+ self.assertEquals(len(s.encode(enc)), expectedsize) |
47 |
+ |
48 |
@bigmemtest(minsize=_2G + 2, memuse=3) |
49 |
def test_encode(self, size): |
50 |
- s = u'.' * size |
51 |
- self.assertEquals(len(s.encode('utf-8')), size) |
52 |
+ return self.basic_encode_test(size, 'utf-8') |
53 |
+ |
54 |
+ @precisionbigmemtest(size=_4G / 6 + 2, memuse=2) |
55 |
+ def test_encode_raw_unicode_escape(self, size): |
56 |
+ try: |
57 |
+ return self.basic_encode_test(size, 'raw_unicode_escape') |
58 |
+ except MemoryError: |
59 |
+ pass # acceptable on 32-bit |
60 |
+ |
61 |
+ @precisionbigmemtest(size=_4G / 5 + 70, memuse=3) |
62 |
+ def test_encode_utf7(self, size): |
63 |
+ try: |
64 |
+ return self.basic_encode_test(size, 'utf7') |
65 |
+ except MemoryError: |
66 |
+ pass # acceptable on 32-bit |
67 |
+ |
68 |
+ @precisionbigmemtest(size=_2G-1, memuse=2) |
69 |
+ def test_decodeascii(self, size): |
70 |
+ return self.basic_encode_test(size, 'ascii', c='A') |
71 |
+ |
72 |
+ @precisionbigmemtest(size=_4G / 5, memuse=6+2) |
73 |
+ def test_unicode_repr_oflw(self, size): |
74 |
+ try: |
75 |
+ s = u"\uAAAA"*size |
76 |
+ r = repr(s) |
77 |
+ except MemoryError: |
78 |
+ pass # acceptable on 32-bit |
79 |
+ else: |
80 |
+ self.failUnless(s == eval(r)) |
81 |
|
82 |
@bigmemtest(minsize=_2G, memuse=2) |
83 |
def test_endswith(self, size): |
84 |
@@ -459,6 +509,11 @@ |
85 |
self.assertEquals(s.count('\\'), size) |
86 |
self.assertEquals(s.count('0'), size * 2) |
87 |
|
88 |
+ @bigmemtest(minsize=2**32 / 5, memuse=6+2) |
89 |
+ def test_unicode_repr(self, size): |
90 |
+ s = u"\uAAAA" * size |
91 |
+ self.failUnless(len(repr(s)) > size) |
92 |
+ |
93 |
# This test is meaningful even with size < 2G, as long as the |
94 |
# doubled string is > 2G (but it tests more if both are > 2G :) |
95 |
@bigmemtest(minsize=_1G + 2, memuse=3) |
96 |
@@ -642,6 +697,35 @@ |
97 |
def test_repeat_large(self, size): |
98 |
return self.basic_test_repeat(size) |
99 |
|
100 |
+ @bigmemtest(minsize=_1G - 1, memuse=12) |
101 |
+ def test_repeat_large_2(self, size): |
102 |
+ return self.basic_test_repeat(size) |
103 |
+ |
104 |
+ @precisionbigmemtest(size=_1G - 1, memuse=9) |
105 |
+ def test_from_2G_generator(self, size): |
106 |
+ try: |
107 |
+ t = tuple(xrange(size)) |
108 |
+ except MemoryError: |
109 |
+ pass # acceptable on 32-bit |
110 |
+ else: |
111 |
+ count = 0 |
112 |
+ for item in t: |
113 |
+ self.assertEquals(item, count) |
114 |
+ count += 1 |
115 |
+ self.assertEquals(count, size) |
116 |
+ |
117 |
+ @precisionbigmemtest(size=_1G - 25, memuse=9) |
118 |
+ def test_from_almost_2G_generator(self, size): |
119 |
+ try: |
120 |
+ t = tuple(xrange(size)) |
121 |
+ count = 0 |
122 |
+ for item in t: |
123 |
+ self.assertEquals(item, count) |
124 |
+ count += 1 |
125 |
+ self.assertEquals(count, size) |
126 |
+ except MemoryError: |
127 |
+ pass # acceptable, expected on 32-bit |
128 |
+ |
129 |
# Like test_concat, split in two. |
130 |
def basic_test_repr(self, size): |
131 |
t = (0,) * size |
132 |
@@ -957,8 +1041,34 @@ |
133 |
self.assertEquals(l[:10], [1] * 10) |
134 |
self.assertEquals(l[-10:], [5] * 10) |
135 |
|
136 |
+class BufferTest(unittest.TestCase): |
137 |
+ |
138 |
+ @precisionbigmemtest(size=_1G, memuse=4) |
139 |
+ def test_repeat(self, size): |
140 |
+ try: |
141 |
+ b = buffer("AAAA")*size |
142 |
+ except MemoryError: |
143 |
+ pass # acceptable on 32-bit |
144 |
+ else: |
145 |
+ count = 0 |
146 |
+ for c in b: |
147 |
+ self.assertEquals(c, 'A') |
148 |
+ count += 1 |
149 |
+ self.assertEquals(count, size*4) |
150 |
+ |
151 |
def test_main(): |
152 |
- test_support.run_unittest(StrTest, TupleTest, ListTest) |
153 |
+ test_support.run_unittest(StrTest, TupleTest, ListTest, BufferTest) |
154 |
+ |
155 |
+# Expected failures (crashers) |
156 |
+# del StrTest.test_center_unicode |
157 |
+del StrTest.test_decodeascii |
158 |
+# del StrTest.test_encode_utf32 |
159 |
+# del StrTest.test_encode_utf7 |
160 |
+# del StrTest.test_encode_raw_unicode_escape |
161 |
+# |
162 |
+# del TupleTest.test_from_2G_generator |
163 |
+# |
164 |
+# del BufferTest.test_repeat |
165 |
|
166 |
if __name__ == '__main__': |
167 |
if len(sys.argv) > 1: |