Skip to content
Prev Previous commit
Next Next commit
do not raise on MAX_REMOTE_STR_READ
  • Loading branch information
maurycy committed Jul 24, 2026
commit 3e58d13d0617e54bc48365d4456f95df2d6a45b6
4 changes: 3 additions & 1 deletion Modules/_remote_debugging/_remote_debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ typedef enum _WIN32_THREADSTATE {
#define SIZEOF_GC_RUNTIME_STATE sizeof(struct _gc_runtime_state)
#define SIZEOF_INTERPRETER_STATE sizeof(PyInterpreterState)

/* Sanity cap for a single string read that are truncated, not rejected. */
#define MAX_REMOTE_STR_READ ((Py_ssize_t)(256 * 1024))

/* Maximum sizes for validation to prevent buffer overflows from corrupted data */
#define MAX_REMOTE_READ ((Py_ssize_t)(256 * 1024)) /* 256 KB max for variable-length object reads */
#define MAX_STACK_CHUNK_SIZE (16 * 1024 * 1024) /* 16 MB max for stack chunks */
#define MAX_LONG_DIGITS 64 /* Allows values up to ~2^1920 */
#define MAX_SET_TABLE_SIZE (1 << 20) /* 1 million entries max for set iteration */
Expand Down
4 changes: 2 additions & 2 deletions Modules/_remote_debugging/object_reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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_REMOTE_READ) {
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;
}
Py_ssize_t read_len = Py_MIN(len, max_len);
Py_ssize_t read_len = Py_MIN(len, Py_MIN(max_len, MAX_REMOTE_STR_READ));
int truncated = read_len != len;

// Inspect state to pick the right data offset and character width.
Expand Down