|
79 | 79 | #define INTERP_STATE_BUFFER_SIZE MAX(INTERP_STATE_MIN_SIZE, 256) |
80 | 80 | #define MAX_STACK_CHUNK_SIZE (16 * 1024 * 1024) /* 16 MB max for stack chunks */ |
81 | 81 | #define MAX_SET_TABLE_SIZE (1 << 20) /* 1 million entries max for set iteration */ |
| 82 | +#define MAX_LONG_DIGITS 64 /* Allows values up to ~2^1920 */ |
82 | 83 |
|
83 | 84 |
|
84 | 85 |
|
@@ -753,6 +754,15 @@ read_py_long( |
753 | 754 | return 0; |
754 | 755 | } |
755 | 756 |
|
| 757 | + if (size < 0 || size > MAX_LONG_DIGITS) { |
| 758 | + PyErr_Format(PyExc_RuntimeError, |
| 759 | + "Invalid PyLong digit count: %zd (expected 0-%d)", |
| 760 | + size, MAX_LONG_DIGITS); |
| 761 | + set_exception_cause(unwinder, PyExc_RuntimeError, |
| 762 | + "Invalid PyLong size (corrupted remote memory)"); |
| 763 | + return -1; |
| 764 | + } |
| 765 | + |
756 | 766 | // If the long object has inline digits, use them directly |
757 | 767 | digit *digits; |
758 | 768 | if (size <= _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS) { |
@@ -1364,6 +1374,9 @@ process_running_task_chain( |
1364 | 1374 | PyObject *coro_chain = PyStructSequence_GET_ITEM(task_info, 2); |
1365 | 1375 | assert(coro_chain != NULL); |
1366 | 1376 | if (PyList_GET_SIZE(coro_chain) != 1) { |
| 1377 | + PyErr_Format(PyExc_RuntimeError, |
| 1378 | + "Expected single-item coro chain, got %zd items", |
| 1379 | + PyList_GET_SIZE(coro_chain)); |
1367 | 1380 | set_exception_cause(unwinder, PyExc_RuntimeError, "Coro chain is not a single item"); |
1368 | 1381 | return -1; |
1369 | 1382 | } |
@@ -1625,6 +1638,7 @@ cache_tlbc_array(RemoteUnwinderObject *unwinder, uintptr_t code_addr, uintptr_t |
1625 | 1638 | void *key = (void *)code_addr; |
1626 | 1639 | if (_Py_hashtable_set(unwinder->tlbc_cache, key, entry) < 0) { |
1627 | 1640 | tlbc_cache_entry_destroy(entry); |
| 1641 | + PyErr_NoMemory(); |
1628 | 1642 | set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to store TLBC entry in cache"); |
1629 | 1643 | return 0; // Cache error |
1630 | 1644 | } |
@@ -1803,7 +1817,11 @@ parse_code_object(RemoteUnwinderObject *unwinder, |
1803 | 1817 | meta->addr_code_adaptive = real_address + (uintptr_t)unwinder->debug_offsets.code_object.co_code_adaptive; |
1804 | 1818 |
|
1805 | 1819 | if (unwinder && unwinder->code_object_cache && _Py_hashtable_set(unwinder->code_object_cache, key, meta) < 0) { |
| 1820 | + func = NULL; |
| 1821 | + file = NULL; |
| 1822 | + linetable = NULL; |
1806 | 1823 | cached_code_metadata_destroy(meta); |
| 1824 | + PyErr_NoMemory(); |
1807 | 1825 | set_exception_cause(unwinder, PyExc_RuntimeError, "Failed to cache code metadata"); |
1808 | 1826 | goto error; |
1809 | 1827 | } |
|
0 commit comments