From 8bdc6c246ac31fe20582fdea446ae26c6d4d0064 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 08:39:41 +0000 Subject: [PATCH 1/3] Initial plan From 3e1ab431718cbc17e3576973ae0c697f9f7516ee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 08:42:30 +0000 Subject: [PATCH 2/3] Change DEFAULT_RECURSE_LIMIT from 511 to 1024 and add nest_limit test Agent-Logs-Url: https://github.com/msgpack/msgpack-python/sessions/d5bc8a6a-e14e-4de3-b55f-4206dc3ca170 Co-authored-by: methane <199592+methane@users.noreply.github.com> --- msgpack/_packer.pyx | 2 +- msgpack/fallback.py | 2 +- test/test_limits.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx index 94d1462c..4d0d2d21 100644 --- a/msgpack/_packer.pyx +++ b/msgpack/_packer.pyx @@ -38,7 +38,7 @@ cdef extern from "pack.h": int msgpack_pack_timestamp(msgpack_packer* x, long long seconds, unsigned long nanoseconds) except -1 -cdef int DEFAULT_RECURSE_LIMIT=511 +cdef int DEFAULT_RECURSE_LIMIT=1024 cdef long long ITEM_LIMIT = (2**32)-1 diff --git a/msgpack/fallback.py b/msgpack/fallback.py index d71bbfc7..1f2daf7b 100644 --- a/msgpack/fallback.py +++ b/msgpack/fallback.py @@ -52,7 +52,7 @@ def newlist_hint(size): TYPE_BIN = 4 TYPE_EXT = 5 -DEFAULT_RECURSE_LIMIT = 511 +DEFAULT_RECURSE_LIMIT = 1024 def _check_type_strict(obj, t, type=type, tuple=tuple): diff --git a/test/test_limits.py b/test/test_limits.py index 9b92b4d9..9774d741 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -153,6 +153,24 @@ def test_auto_max_array_len(): unpacker.unpack() +def test_nest_limit_1024(): + import sys + + # Build a list nested 1024 levels deep + d = None + for _ in range(1024): + d = [d] + + # Temporarily raise Python's recursion limit so packing 1024 levels succeeds + old_limit = sys.getrecursionlimit() + sys.setrecursionlimit(max(old_limit, 10000)) + try: + packed = packb(d) + assert unpackb(packed) == d + finally: + sys.setrecursionlimit(old_limit) + + def test_auto_max_map_len(): # len(packed) == 6 -> max_map_len == 3 packed = b"\xde\x00\x04zzz" From 30e46c8d14e76a54fda419788fe377bb5386c019 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 14:31:14 +0000 Subject: [PATCH 3/3] Fix test_nest_limit_1024: use iterative comparison to avoid C-level recursion limit Agent-Logs-Url: https://github.com/msgpack/msgpack-python/sessions/b5597430-50ea-4c37-b94f-7b4c9ed4142c Co-authored-by: methane <199592+methane@users.noreply.github.com> --- test/test_limits.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_limits.py b/test/test_limits.py index 9774d741..468c1c36 100644 --- a/test/test_limits.py +++ b/test/test_limits.py @@ -166,10 +166,16 @@ def test_nest_limit_1024(): sys.setrecursionlimit(max(old_limit, 10000)) try: packed = packb(d) - assert unpackb(packed) == d + result = unpackb(packed) finally: sys.setrecursionlimit(old_limit) + # Verify structure iteratively to avoid hitting C-level recursion limit in == + for _ in range(1024): + assert isinstance(result, list) and len(result) == 1 + result = result[0] + assert result is None + def test_auto_max_map_len(): # len(packed) == 6 -> max_map_len == 3