-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
TextIOWrapper.reconfigure() crashes if encoding is not string or None #111942
Comments
* Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments.
* Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments.
…-111976) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments. (cherry picked from commit ee06fff) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…-111976) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments. (cherry picked from commit ee06fff) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…) (GH-112058) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments. (cherry picked from commit ee06fff) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked.
In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked.
Weird. The address sanitizer tests were passed in main and 3.12, but failed in 3.11. And I now can reproduce the failure locally in main. The newly added tests exposed a bug in the |
The error handler is not tested in the _io extension. It's only tested if Python is built in debug mode (Py_DEBUG) or if the Python Development Mode (-X dev) is enabled.
In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org>
…thonGH-112061) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. (cherry picked from commit 9302f05) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
…thon#112061) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 9302f05)
…thon#112061) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 9302f05)
…H-112061) (GH-112089) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 9302f05) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…tor (pythonGH-112061) (pythonGH-112089) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit 9302f05) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…) (GH-112059) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments. (cherry picked from commit ee06fff) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Nice thanks, thanks. |
…-111976) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments.
…thon#112061) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org>
…-111976) * Fix crash when encoding is not string or None. * Fix crash when both line_buffering and write_through raise exception when converted ti int. * Add a number of tests for constructor and reconfigure() method with invalid arguments.
…thon#112061) In non-debug more the check for the "errors" argument is skipped, and then PyUnicode_AsUTF8() can fail, but its result was not checked. Co-authored-by: Victor Stinner <vstinner@python.org>
There's an issue with the 3.11 backport, in + Py_INCREF(errors);
...
Py_SETREF(self->encoding, encoding);
- Py_SETREF(self->errors, Py_NewRef(errors));
+ Py_SETREF(self->errors, errors); but in 3.11 this is: + Py_INCREF(errors);
...
Py_INCREF(errors);
Py_SETREF(self->encoding, encoding);
Py_SETREF(self->errors, errors); i.e. there's an extra incref, but it looks -- at least to Git -- like the change that removes This was not caught because I'm preparing a fix. |
…e_encoding There's an issue with the 3.11 backport commit e2421a3 The chane for the main branch was: ```diff + Py_INCREF(errors); ... Py_SETREF(self->encoding, encoding); - Py_SETREF(self->errors, Py_NewRef(errors)); + Py_SETREF(self->errors, errors); ``` but in 3.11 this became: ```diff + Py_INCREF(errors); ... Py_INCREF(errors); Py_SETREF(self->encoding, encoding); Py_SETREF(self->errors, errors); ``` i.e. there's an extra incref, but it looks -- at least to Git -- like the change that removes `Py_NewRef` was already applied. This was not caught because `test_io` refleaks tests were ineffective on 3.11 (see python#126478 (comment)). Remove the extraneous incref.
Crash report
What happened?
Unlike to
TextIOWrapper
constructor,TextIOWrapper.reconfigure()
does not check that the encoding argument is actually None or string. If it is not None, it calls_PyUnicode_EqualToASCIIString
that only works with strings and crashes in debug build. There may be other similar errors in other arguments.CPython versions tested on:
3.10, 3.11, 3.12
Operating systems tested on:
No response
Output from running 'python -VV' on the command line:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: