https://github.com/python/cpython/commit/0d234a2475a62f8676796298afc7f7eb981af0ba commit: 0d234a2475a62f8676796298afc7f7eb981af0ba branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-10-20T11:12:02-07:00 summary:
[3.14] gh-159739: Handle module filename encoding errors (GH-159749) (#159842) Propagate UTF-8 conversion errors before copying the module filename. (cherry picked from commit 9e262af9aebbad2abc975649036d6fc455bcb194) Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.09590b.rst M Objects/moduleobject.c diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.09590b.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.09590b.rst new file mode 100644 index 00000000000000..3231be417aa80e --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.09590b.rst @@ -0,0 +1 @@ +Avoid a crash when a module filename cannot be encoded as UTF-8. diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 162a43c18bce72..5c0d11b1784ef6 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -686,6 +686,10 @@ _PyModule_GetFilenameUTF8(PyObject *mod, char *buffer, Py_ssize_t maxlen) } else { const char *filename = PyUnicode_AsUTF8AndSize(filenameobj, &size); + if (filename == NULL) { + Py_DECREF(filenameobj); + return -1; + } assert(size >= 0); if (size > maxlen) { size = -1; _______________________________________________ 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]
