Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ def test_signatures(self):
str(inspect.signature(traceback.format_exception_only)),
'(exc, /, value=<implicit>, *, show_group=False, **kwargs)')

def test_traceback_deep_recursion_alloca(self):

def recurse(n):
if n == 0:
raise RuntimeError("boom")
return recurse(n - 1)
try:
recurse(50)
except RuntimeError as exc:
tb = traceback.format_exception(exc)
assert any("RuntimeError" in line for line in tb)


class PurePythonExceptionFormattingMixin:
def get_exception(self, callable, slice_start=0, slice_end=-1):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix incorrect memory allocation in the VLA fallback macro in traceback.c
when using alloca(), preventing potential out-of-bounds access.
2 changes: 1 addition & 1 deletion Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#if defined(__STDC_NO_VLA__) && (__STDC_NO_VLA__ == 1)
/* Use alloca() for VLAs. */
# define VLA(type, name, size) type *name = alloca(size)
# define VLA(type, name, size) type *name = (type *)alloca(sizeof(type) * (size))
#elif !defined(__STDC_NO_VLA__) || (__STDC_NO_VLA__ == 0)
/* Use actual C VLAs.*/
# define VLA(type, name, size) type name[size]
Expand Down
Loading