Skip to content

gh-159398: Validate strings read from remote process in _remote_debugging - #159402

Merged
StanFromIreland merged 5 commits into
python:mainfrom
StanFromIreland:gh-159398
Oct 30, 2026
Merged

StanFromIreland merged 5 commits into
python:mainfrom
StanFromIreland:gh-159398

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Instead of copying the remote bytes straight into a str, we now read them into a temp buffer and build the result with PyUnicode_FromKindAndData, which validates the characters and picks the narrowest kind. Bad names raise an error so we end up with <unknown function>.

Comment thread Modules/_testinternalcapi.c Resolved
Co-authored-by: vstinner@python.org
@maurycy

maurycy commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

I reran the Tools/inspection/oracle_external_inspection.py on macOS, no change.

Comment thread Lib/test/test_external_inspection.py Resolved
Comment thread Lib/test/test_external_inspection.py Resolved
@vstinner vstinner added the needs backport to 3.15 bugs and security fixes label Oct 15, 2026
@vstinner

Copy link
Copy Markdown
Member

In Python 3.14, read_py_str() of Modules/_remote_debugging_module.c calls PyUnicode_FromStringAndSize(). I don't get how it works. It reads the UTF-8 representation of a string? What if the Unicode object has no UTF-8 representation? So it's unclear to me if Python 3.14 is also affected by the issue.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just some minor suggestions.

Comment thread Modules/_testinternalcapi.c Resolved
Comment thread Lib/test/test_external_inspection.py Resolved
StanFromIreland and others added 3 commits October 16, 2026 16:04
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-Authored-By: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>

@maurycy maurycy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@StanFromIreland

Copy link
Copy Markdown
Member Author

@pablogsal is it alright to merge?

@nascheme

Copy link
Copy Markdown
Member

FYI, I'm seeing CI failures for ASan build due to this bug. The error log is:

test_sampling_basic_functionality (test.test_profiling.test_sampling_profiler.test_integration.TestSampleProfilerIntegration.test_sampling_basic_functionality) ... 
Objects/unicodeobject.c:675: _PyUnicode_CheckConsistency: Assertion failed: maxchar <= 0x10ffff 
Enable tracemalloc to get the memory block allocation traceback 
 
object address  : 0x73262a8477b0 
object refcount : 2 
object type     : 0x558481fe4680 
object type name: str 
object repr     : '\Ufdfdfdfd' 
 
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed 
Python runtime state: initialized

@StanFromIreland

Copy link
Copy Markdown
Member Author

Yes it's been annoying me too, I'll merge tomorrow if there are no more comments.

@StanFromIreland
StanFromIreland merged commit 1374fde into python:main Oct 30, 2026
120 of 123 checks passed
@StanFromIreland
StanFromIreland deleted the gh-159398 branch October 30, 2026 10:31
@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 30, 2026

Copy link
Copy Markdown

GH-160963 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 30, 2026
StanFromIreland added a commit that referenced this pull request Oct 30, 2026
…remote_debugging` (GH-159402) (#160963)

(cherry picked from commit 1374fde)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants