From 0102cf08cfff623372ba642705a88cf8cb9e43cf Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Thu, 16 Mar 2023 17:24:48 +0900 Subject: [PATCH 1/3] gh-102701: Fix overflow in dictobject.c --- .../2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst | 1 + Objects/dictobject.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-03-16-17-24-44.gh-issue-102701.iNGVaS.rst 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 00000000000000..4e1f31893377ba --- /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 227e438a8dfffc..53f9a380346a0d 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< Date: Fri, 17 Mar 2023 04:49:38 +0000 Subject: [PATCH 2/3] Add testcase --- Lib/test/test_bigmem.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 859f1539e20b80..42628382e18f2e 100644 --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -1248,6 +1248,15 @@ def test_sort(self, size): 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]) From b35172f1bab523b3cad55336b66d307a87fa7dea Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 17 Mar 2023 15:35:57 +0900 Subject: [PATCH 3/3] Fix indent --- Lib/test/test_bigmem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_bigmem.py b/Lib/test/test_bigmem.py index 42628382e18f2e..c9ab1c1de9e186 100644 --- a/Lib/test/test_bigmem.py +++ b/Lib/test/test_bigmem.py @@ -1250,11 +1250,11 @@ def test_sort(self, size): 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 + @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__':