-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
bpo-32583: Fix possible crashing in builtin Unicode decoders #5325
Conversation
298adef
to
648a61d
Compare
When using customized decode error handlers, it is possible for builtin decoders to write out-of-bounds and then crash.
648a61d
to
1c7c83a
Compare
@zhangyangyu: Please replace |
Thanks @zhangyangyu for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
Sorry, @zhangyangyu, I could not cleanly backport this to |
…ythonGH-5325) When using customized decode error handlers, it is possible for builtin decoders to write out-of-bounds and then crash.. (cherry picked from commit 2c7fd46)
GH-5459 is a backport of this pull request to the 3.6 branch. |
} | ||
new_inptr = *input + newpos; | ||
if (*inend - new_inptr > remain) { | ||
/* We don't know the decoding algorithm here so we make the worst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handler registered with codecs.register_error
can produce any string as an output. This output will be inserted in the buffer you allocate. So I propose to expect that decoded output could be bigger and either check that and reallocate the buffer or raise a MemoryError exception with proper description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review @sibiryakov . But the situation you mention has already been handled. See the previous condition replen - 1
, if the handler returns any string longer than one, need_to_grow
will be set and we will allocate more memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great @zhangyangyu! Thank you!
…5325) When using customized decode error handlers, it is possible for builtin decoders to write out-of-bounds and then crash.
https://bugs.python.org/issue32583