Skip to content

Commit 14326da

Browse files
[3.14] gh-142662: Fix interpreter startup crash when codecs are not initialized yet (GH-161860) (#161947)
gh-142662: Fix interpreter startup crash when `codecs` are not initialized yet (GH-161860) (cherry picked from commit 2c2d801) Co-authored-by: sobolevn <[email protected]>
1 parent 65dfc16 commit 14326da

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎Python/codecs.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ PyObject *_PyCodec_Lookup(const char *encoding)
146146
}
147147

148148
PyInterpreterState *interp = _PyInterpreterState_GET();
149-
assert(interp->codecs.initialized);
149+
if (!interp->codecs.initialized) {
150+
PyErr_SetString(PyExc_SystemError, "Codecs are not initialized");
151+
return NULL;
152+
}
150153

151154
/* Convert the encoding to a normalized Python string: all
152155
characters are converted to lower case, spaces and hyphens are

0 commit comments

Comments
 (0)