From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:54:18 +0000 (-0700) Subject: gh-102701: Fix overflow in dictobject.c (GH-102750) X-Git-Tag: v3.11.3~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f967aee4fbb9f417028426568230e2091d95f0fe;p=thirdparty%2FPython%2Fcpython.git gh-102701: Fix overflow in dictobject.c (GH-102750) (cherry picked from commit 65fb7c4055f280caaa970939d16dd947e6df8a8d) Co-authored-by: Inada Naoki --- diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 859f1539e20b..c9ab1c1de9e1 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 000000000000..4e1f31893377 --- /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 4a214f8cf5b7..69a4a865103c 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -600,7 +600,7 @@ new_keys_object(uint8_t log2_size, bool unicode) assert(log2_size >= PyDict_LOG_MINSIZE); - usable = USABLE_FRACTION(1<