mirror of https://github.com/python/cpython
gh-102701: Fix overflow in dictobject.c (GH-102750)
This commit is contained in:
parent
4f5774f648
commit
65fb7c4055
|
@ -1248,6 +1248,15 @@ class ListTest(unittest.TestCase):
|
||||||
self.assertEqual(l[-10:], [5] * 10)
|
self.assertEqual(l[-10:], [5] * 10)
|
||||||
|
|
||||||
|
|
||||||
|
class DictTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@bigmemtest(size=357913941, memuse=160)
|
||||||
|
def test_dict(self, size):
|
||||||
|
# https://github.com/python/cpython/issues/102701
|
||||||
|
d = dict.fromkeys(range(size))
|
||||||
|
d[size] = 1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
support.set_memlimit(sys.argv[1])
|
support.set_memlimit(sys.argv[1])
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix overflow when creating very large dict.
|
|
@ -596,7 +596,7 @@ new_keys_object(PyInterpreterState *interp, uint8_t log2_size, bool unicode)
|
||||||
|
|
||||||
assert(log2_size >= PyDict_LOG_MINSIZE);
|
assert(log2_size >= PyDict_LOG_MINSIZE);
|
||||||
|
|
||||||
usable = USABLE_FRACTION(1<<log2_size);
|
usable = USABLE_FRACTION((size_t)1<<log2_size);
|
||||||
if (log2_size < 8) {
|
if (log2_size < 8) {
|
||||||
log2_bytes = log2_size;
|
log2_bytes = log2_size;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue