diff options
author | Inada Naoki <songofacandy@gmail.com> | 2023-03-17 13:39:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-17 13:39:09 (GMT) |
commit | 65fb7c4055f280caaa970939d16dd947e6df8a8d (patch) | |
tree | 289309d1d747d2a101a9f54e239126baedd35c2b | |
parent | 4f5774f648eafd1a7076ecf9af9629fb81baa363 (diff) | |
download | cpython-65fb7c4055f280caaa970939d16dd947e6df8a8d.zip cpython-65fb7c4055f280caaa970939d16dd947e6df8a8d.tar.gz cpython-65fb7c4055f280caaa970939d16dd947e6df8a8d.tar.bz2 |
gh-102701: Fix overflow in dictobject.c (GH-102750)
-rw-r--r-- | Lib/test/test_bigmem.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst | 1 | ||||
-rw-r--r-- | Objects/dictobject.c | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 859f153..c9ab1c1 100644 --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -1248,6 +1248,15 @@ class ListTest(unittest.TestCase): 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 len(sys.argv) > 1: support.set_memlimit(sys.argv[1]) diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst b/Misc/NEWS.d/next/Core and Builtins/2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst new file mode 100644 index 0000000..4e1f318 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst @@ -0,0 +1 @@ +Fix overflow when creating very large dict. diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 227e438..53f9a38 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -596,7 +596,7 @@ new_keys_object(PyInterpreterState *interp, uint8_t log2_size, bool unicode) assert(log2_size >= PyDict_LOG_MINSIZE); - usable = USABLE_FRACTION(1<<log2_size); + usable = USABLE_FRACTION((size_t)1<<log2_size); if (log2_size < 8) { log2_bytes = log2_size; } |