Skip to content

Commit 5ab5ea2

Browse files
committed
fix: translate RecursionError to StackError in fallback Unpacker.skip()
skip() was the only unpack entry point in fallback.py that let a RecursionError escape on deeply nested input; unpack() and __next__() both re-raise it as StackError, and the C extension raises StackError on this path too. Callers guarding against adversarial nesting with except StackError/ValueError were unprotected when skipping. Wrap the body the same way unpack() does, leaving _consume() outside the try so the post-failure buffer state matches.
1 parent 9f9bdae commit 5ab5ea2

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

msgpack/fallback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ def __next__(self):
582582
next = __next__
583583

584584
def skip(self):
585-
self._unpack(EX_SKIP)
585+
try:
586+
self._unpack(EX_SKIP)
587+
except RecursionError:
588+
raise StackError
586589
self._consume()
587590

588591
def unpack(self):

test/test_except.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def test_invalidvalue():
9797
with raises(StackError):
9898
unpackb(b"\x91" * 3000) # nested fixarray(len=1)
9999

100+
with raises(StackError):
101+
unpacker = Unpacker()
102+
unpacker.feed(b"\x91" * 3000)
103+
unpacker.skip()
104+
100105

101106
def test_no_memory_leak_on_nested_invalid_tag() -> None:
102107
"""Regression test: unpacking nested arrays containing an invalid tag must not leak objects."""

0 commit comments

Comments
 (0)