Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a85bf3

Browse filesBrowse files
gh-111942: Fix SystemError in the TextIOWrapper constructor
In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked.
1 parent 0ff6368 commit 0a85bf3
Copy full SHA for 0a85bf3

File tree

2 files changed

+8
-2
lines changed
Filter options

2 files changed

+8
-2
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix SystemError in the TextIOWrapper constructor with non-encodable "errors"
2+
argument in non-debug mode.

‎Modules/_io/textio.c

Copy file name to clipboardExpand all lines: Modules/_io/textio.c
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11121112
else if (io_check_errors(errors)) {
11131113
return -1;
11141114
}
1115+
const char *errors_str = PyUnicode_AsUTF8(errors);
1116+
if (errors_str == NULL) {
1117+
return -1;
1118+
}
11151119

11161120
if (validate_newline(newline) < 0) {
11171121
return -1;
@@ -1184,11 +1188,11 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11841188
/* Build the decoder object */
11851189
_PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
11861190
self->state = state;
1187-
if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
1191+
if (_textiowrapper_set_decoder(self, codec_info, errors_str) != 0)
11881192
goto error;
11891193

11901194
/* Build the encoder object */
1191-
if (_textiowrapper_set_encoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
1195+
if (_textiowrapper_set_encoder(self, codec_info, errors_str) != 0)
11921196
goto error;
11931197

11941198
/* Finished sorting out the codec details */

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.