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

gh-111942: Fix SystemError in the TextIOWrapper constructor #112061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
serhiy-storchaka committed Nov 14, 2023
commit 0a85bf3081010ba5dd2d57c261a2c0dae2ba412d
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix SystemError in the TextIOWrapper constructor with non-encodable "errors"
argument in non-debug mode.
8 changes: 6 additions & 2 deletions 8 Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,10 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
else if (io_check_errors(errors)) {
return -1;
}
const char *errors_str = PyUnicode_AsUTF8(errors);
vstinner marked this conversation as resolved.
Show resolved Hide resolved
if (errors_str == NULL) {
return -1;
}

if (validate_newline(newline) < 0) {
return -1;
Expand Down Expand Up @@ -1184,11 +1188,11 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
/* Build the decoder object */
_PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
self->state = state;
if (_textiowrapper_set_decoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
if (_textiowrapper_set_decoder(self, codec_info, errors_str) != 0)
goto error;

/* Build the encoder object */
if (_textiowrapper_set_encoder(self, codec_info, PyUnicode_AsUTF8(errors)) != 0)
if (_textiowrapper_set_encoder(self, codec_info, errors_str) != 0)
goto error;

/* Finished sorting out the codec details */
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.