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
PyThread_create_key(): fix comparison between signed and unsigned numbers in Python/thread_pthread.h #66402
Comments
The issue bpo-22110 enabled more compiler warnings. I would like to fix this one: Attached patch uses Py_SAFE_DOWNCAST() to explicitly downcast to int. On Linux (on my Fedora 20/amd64), pthread_key_t is defined as an unsigned int, whereas the result type of PyThread_create_key is a signed int. Nobody complained before, so I get that nobody noticed the possible overflow for a key > INT_MAX. I checked the code, we only check if PyThread_create_key() returns -1, if you reach UINT_MAX keys. UINT_MAX keys sounds insane, you probably hit another limit before. On Linux, it looks like the key is a counter and deleted values are reused: haypo@selma$ ./python
Python 3.5.0a0 (default:a0b38f4eb79e, Aug 15 2014, 23:37:42)
[GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.pythonapi.PyThread_create_key()
2
>>> ctypes.pythonapi.PyThread_create_key()
3
>>> ctypes.pythonapi.PyThread_create_key()
4
>>> ctypes.pythonapi.PyThread_delete_key(3)
0
>>> ctypes.pythonapi.PyThread_create_key()
3 |
pthread_key_create_overflow.patch: safer patch, delete the newly created key and return an error on integer overflow. |
New changeset 1b898b5d5ffe by Victor Stinner in branch 'default': |
I fixed the issue in Python 3.5, I close the issue. Even if Python 2.7 and 3.4 are also affected, I prefer to not modify them to not take the risk of introducing a regression for a corner case. |
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: