Skip to content

Commit b538145

Browse files
methaneFidget-Spinner
authored andcommitted
pythongh-102701: Fix overflow in dictobject.c (pythonGH-102750)
1 parent 8d2b6b5 commit b538145

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_bigmem.py

+9
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,15 @@ def test_sort(self, size):
12481248
self.assertEqual(l[-10:], [5] * 10)
12491249

12501250

1251+
class DictTest(unittest.TestCase):
1252+
1253+
@bigmemtest(size=357913941, memuse=160)
1254+
def test_dict(self, size):
1255+
# https://github.com/python/cpython/issues/102701
1256+
d = dict.fromkeys(range(size))
1257+
d[size] = 1
1258+
1259+
12511260
if __name__ == '__main__':
12521261
if len(sys.argv) > 1:
12531262
support.set_memlimit(sys.argv[1])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix overflow when creating very large dict.

Objects/dictobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ new_keys_object(PyInterpreterState *interp, uint8_t log2_size, bool unicode)
596596

597597
assert(log2_size >= PyDict_LOG_MINSIZE);
598598

599-
usable = USABLE_FRACTION(1<<log2_size);
599+
usable = USABLE_FRACTION((size_t)1<<log2_size);
600600
if (log2_size < 8) {
601601
log2_bytes = log2_size;
602602
}

0 commit comments

Comments
 (0)