Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.3k
gh-146308: Fix error handling issues in _remote_debugging module#146309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
pablogsal merged 3 commits intopython:mainfrompablogsal:gh-146308-fix-remote-debugging-error-handlingMar 22, 2026
+85 −19
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletionsMisc/NEWS.d/next/Core_and_Builtins/2026-03-22-19-30-00.gh-issue-146308.AxnRVA.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fixed multiple error handling issues in the :mod:`!_remote_debugging` module | ||
| including a double-free in code object caching, memory leaks on allocation | ||
| failure, missing exception checks in binary format varint decoding, reference | ||
| leaks on error paths in frame chain processing, and inconsistent thread status | ||
| error reporting across platforms. Patch by Pablo Galindo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -571,15 +571,16 @@ reader_get_or_create_thread_state(BinaryReader *reader, uint64_t thread_id, | ||
| return NULL; | ||
| } | ||
| } else if (reader->thread_state_count >= reader->thread_state_capacity) { | ||
| ReaderThreadState *new_states = grow_array(reader->thread_states, | ||
| &reader->thread_state_capacity, | ||
| sizeof(ReaderThreadState)); | ||
| if (!new_states) { | ||
| return NULL; | ||
| } | ||
| reader->thread_states = new_states; | ||
| } | ||
| ReaderThreadState *ts = &reader->thread_states[reader->thread_state_count]; | ||
| memset(ts, 0, sizeof(ReaderThreadState)); | ||
| ts->thread_id = thread_id; | ||
| ts->interpreter_id = interpreter_id; | ||
| @@ -590,6 +591,9 @@ reader_get_or_create_thread_state(BinaryReader *reader, uint64_t thread_id, | ||
| PyErr_NoMemory(); | ||
| return NULL; | ||
| } | ||
| // Increment count only after successful allocation to avoid | ||
| // leaving a half-initialized entry visible to future lookups | ||
| reader->thread_state_count++; | ||
| return ts; | ||
| } | ||
| @@ -604,7 +608,11 @@ static inline int | ||
| decode_stack_full(ReaderThreadState *ts, const uint8_t *data, | ||
| size_t *offset, size_t max_size) | ||
| { | ||
| size_t prev_offset = *offset; | ||
| uint32_t depth = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| /* Validate depth against capacity to prevent buffer overflow */ | ||
| if (depth > ts->current_stack_capacity) { | ||
| @@ -615,7 +623,11 @@ decode_stack_full(ReaderThreadState *ts, const uint8_t *data, | ||
| ts->current_stack_depth = depth; | ||
| for (uint32_t i = 0; i < depth; i++) { | ||
| size_t prev_offset = *offset; | ||
| ts->current_stack[i] = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
| @@ -627,8 +639,16 @@ static inline int | ||
| decode_stack_suffix(ReaderThreadState *ts, const uint8_t *data, | ||
| size_t *offset, size_t max_size) | ||
| { | ||
| size_t prev_offset = *offset; | ||
| uint32_t shared = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| prev_offset = *offset; | ||
| uint32_t new_count = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| /* Validate shared doesn't exceed current stack depth */ | ||
| if (shared > ts->current_stack_depth) { | ||
| @@ -664,7 +684,11 @@ decode_stack_suffix(ReaderThreadState *ts, const uint8_t *data, | ||
| } | ||
| for (uint32_t i = 0; i < new_count; i++) { | ||
| size_t prev_offset = *offset; | ||
| ts->current_stack[i] = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| } | ||
| ts->current_stack_depth = final_depth; | ||
| return 0; | ||
| @@ -677,8 +701,16 @@ static inline int | ||
| decode_stack_pop_push(ReaderThreadState *ts, const uint8_t *data, | ||
| size_t *offset, size_t max_size) | ||
| { | ||
| size_t prev_offset = *offset; | ||
| uint32_t pop = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| prev_offset = *offset; | ||
| uint32_t push = decode_varint_u32(data, offset, max_size); | ||
| if (*offset == prev_offset) { | ||
| return -1; | ||
| } | ||
| size_t keep = (ts->current_stack_depth > pop) ? ts->current_stack_depth - pop : 0; | ||
| /* Validate final depth doesn't exceed capacity */ | ||
| @@ -699,7 +731,12 @@ decode_stack_pop_push(ReaderThreadState *ts, const uint8_t *data, | ||
| } | ||
| for (uint32_t i = 0; i < push; i++) { | ||
| size_t prev_offset = *offset; | ||
| ts->current_stack[i] = decode_varint_u32(data, offset, max_size); | ||
| /* If offset didn't advance, varint decoding failed */ | ||
| if (*offset == prev_offset) { | ||
pablogsal marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return -1; | ||
| } | ||
| } | ||
| ts->current_stack_depth = final_depth; | ||
| return 0; | ||
| @@ -1222,6 +1259,9 @@ binary_reader_close(BinaryReader *reader) | ||
| reader->mapped_data = NULL; /* Prevent use-after-free */ | ||
| reader->mapped_size = 0; | ||
| } | ||
| /* Clear sample_data which may point into the now-unmapped region */ | ||
| reader->sample_data = NULL; | ||
| reader->sample_data_size = 0; | ||
| if (reader->fd >= 0) { | ||
| close(reader->fd); | ||
| reader->fd = -1; /* Mark as closed */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.