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
17 changes: 17 additions & 0 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import asyncio
import os
import textwrap
import importlib
Expand Down Expand Up @@ -66,6 +67,22 @@ def get_all_awaited_by(pid):
class TestGetStackTrace(unittest.TestCase):
maxDiff = None

@skip_if_not_supported
def test_long_task_name_is_truncated(self):
# gh-157788
async def main():
asyncio.create_task(asyncio.sleep(10_000), name="x" * 300)
await asyncio.sleep(0)
return [
task.task_name
for info in RemoteUnwinder(os.getpid()).get_all_awaited_by()
for task in info.awaited_by
]

names = asyncio.run(main())
self.assertIn("Task-1", names)
self.assertEqual([len(n) for n in names if n.startswith("x")], [255])

@skip_if_not_supported
@unittest.skipIf(
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``python -m asyncio ps`` failing on a process that has a task with a
name longer than 255 characters.
6 changes: 5 additions & 1 deletion Modules/_remote_debugging_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,12 +1109,16 @@ read_py_str(
}

Py_ssize_t len = GET_MEMBER(Py_ssize_t, unicode_obj, unwinder->debug_offsets.unicode_object.length);
if (len < 0 || len > max_len) {
if (len < 0) {
PyErr_Format(PyExc_RuntimeError,
"Invalid string length (%zd) at 0x%lx", len, address);
set_exception_cause(unwinder, PyExc_RuntimeError, "Invalid string length in remote Unicode object");
return NULL;
}
if (len > max_len) {
// gh-157788: a long name must not fail the whole read
len = max_len;
}

buf = (char *)PyMem_RawMalloc(len+1);
if (buf == NULL) {
Expand Down
Loading