Skip to content

Commit b20f7a7

Browse files
jelle-openaiJelleZijlstra
authored andcommitted
gh-159739: Handle module filename encoding errors (GH-159749)
Propagate UTF-8 conversion errors before copying the module filename. (cherry picked from commit 9e262af) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 3742966 commit b20f7a7

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Avoid a crash when a module filename cannot be encoded as UTF-8.

‎Objects/moduleobject.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,10 @@ _PyModule_GetFilenameUTF8(PyObject *mod, char *buffer, Py_ssize_t maxlen)
686686
}
687687
else {
688688
const char *filename = PyUnicode_AsUTF8AndSize(filenameobj, &size);
689+
if (filename == NULL) {
690+
Py_DECREF(filenameobj);
691+
return -1;
692+
}
689693
assert(size >= 0);
690694
if (size > maxlen) {
691695
size = -1;

0 commit comments

Comments
 (0)