Skip to content
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

gh-127182: Fix io.StringIO.__setstate__ crash when None is the first value #127219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Nov 24, 2024

Change:

  • We now check for explicit None value in __setstate__, it cannot be recieved normally, because __getstate__ never returns None, but we should not let a simple direct call to crash, when the fix is rather simple
  • Why does it happen in the first place? Because we do the input validation with __init__ method:
    if (_io_StringIO___init__((PyObject *)self, initarg, NULL) < 0) {
  • But, None is an allowed input value, see
    if (value && value != Py_None && !PyUnicode_Check(value)) {
  • We did not check for None in __setstate__
  • NULL cannot be passed to __setstate__, because it requires a tuple input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant