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
Add range check for %c in PyUnicode_FromFormat #62384
Comments
Currently PyUnicode_FromFormat doesn't check an argument for %c and can raise SystemError only due maxchar check in PyUnicode_New. On 2.7 an error doesn't raised, but %c argument can be silently wrapped (on narrow build) or illegal Unicode string can be created (on wide build). The proposed patch adds explicit range check for %c argument. |
Both patches look good to me. Do you feel motivated to check if all formating methods have a test? Here is a list of format methods: PyUnicode_Format():
PyUnicode_FromFromatV():
int.__format__('c'):
IMO a ValueError would be better than OverflowError, it's not really an overflow (limitation of the C language, or a C type). It is maybe too late to change this. |
No, I don't feel motivated right now (and this is a case when even never is better than right now). I checked other format methods and found a bug only in PyUnicode_FromFormatV(). I had added test for 3.3+ because 3.3+ already have a test for PyUnicode_FromFormatV(). I hadn't add test for 2.7 because there is no test for PyUnicode_FromFormatV() on 2.7. |
New changeset f8ede55cf92b by Serhiy Storchaka in branch '3.3': New changeset 42def600210e by Serhiy Storchaka in branch 'default': New changeset 2f1e8b7fa534 by Serhiy Storchaka in branch '2.7': |
I agree, a ValueError may be better than OverflowError, but all other formattings raise OverflowError, and we should support them consistent. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: