https://github.com/python/cpython/commit/d3369c2f6749a91b1dbe4e3007f22f54e6403d79
commit: d3369c2f6749a91b1dbe4e3007f22f54e6403d79
branch: 3.14
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-09-18T21:35:08Z
summary:
[3.14] gh-156114: Fix crash in perf trampoline with unencodable code names
(GH-156300) (#157775)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst
M Lib/test/test_perf_profiler.py
M Python/perf_jit_trampoline.c
M Python/perf_trampoline.c
diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py
index f46331ced2abb0b..c90e1b8e056b923 100644
--- a/Lib/test/test_perf_profiler.py
+++ b/Lib/test/test_perf_profiler.py
@@ -113,6 +113,16 @@ def baz():
"Address should contain only hex characters",
)
+ @unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT
instrumented binaries")
+ def test_trampoline_with_unencodable_name(self):
+ code = """if 1:
+ import sys
+
+ sys.activate_stack_trampoline("perf")
+ eval(compile("pass", "bad\\ud800file", "exec"))
+ """
+ assert_python_ok("-c", code, PYTHON_JIT="0")
+
@unittest.skipIf(support.check_bolt_optimized(), "fails on BOLT
instrumented binaries")
def test_trampoline_works_with_forks(self):
code = """if 1:
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst
new file mode 100644
index 000000000000000..096216f7e6c7b3c
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-23-12-00-00.gh-issue-156114.Kq7fXz.rst
@@ -0,0 +1,2 @@
+Fix a crash in the perf trampoline when a code object has a name or filename
+that cannot be encoded to UTF-8. Patched by Shamil Abdulaev.
diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c
index 33c37e2f0ddb414..1fca943b5d02bd1 100644
--- a/Python/perf_jit_trampoline.c
+++ b/Python/perf_jit_trampoline.c
@@ -1166,11 +1166,19 @@ static void perf_map_jit_write_entry(void *state, const
void *code_addr,
const char *entry = "";
if (co->co_qualname != NULL) {
entry = PyUnicode_AsUTF8(co->co_qualname);
+ if (entry == NULL) {
+ PyErr_Clear();
+ entry = "";
+ }
}
const char *filename = "";
if (co->co_filename != NULL) {
filename = PyUnicode_AsUTF8(co->co_filename);
+ if (filename == NULL) {
+ PyErr_Clear();
+ filename = "";
+ }
}
/*
diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c
index 8e7cfff33ebfcd4..40f202360e80d69 100644
--- a/Python/perf_trampoline.c
+++ b/Python/perf_trampoline.c
@@ -255,10 +255,18 @@ perf_map_write_entry(void *state, const void *code_addr,
const char *entry = "";
if (co->co_qualname != NULL) {
entry = PyUnicode_AsUTF8(co->co_qualname);
+ if (entry == NULL) {
+ PyErr_Clear();
+ entry = "";
+ }
}
const char *filename = "";
if (co->co_filename != NULL) {
filename = PyUnicode_AsUTF8(co->co_filename);
+ if (filename == NULL) {
+ PyErr_Clear();
+ filename = "";
+ }
}
size_t perf_map_entry_size = snprintf(NULL, 0, "py::%s:%s", entry,
filename) + 1;
char* perf_map_entry = (char*) PyMem_RawMalloc(perf_map_entry_size);
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]