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
os.urandom(1.1): infinite loop #47958
Comments
Calling os.urandom(1 + float(x)) ends in a infinite loop due to a naive while len(bytes) < n:
bytes += read(_urandomfd, n - len(bytes)) Trivial patch attached. |
i'll fix this and add a unit test. |
better patch with tests attached, no explicit int conversion is done. i also wrapped the use of the fd returned by open with a try: finally: |
The explicit int() conversion looked saner to me, rather than passing a |
if i did n = int(n) that would change the API to allow bytes/unicode to be passed in which by not doing the int conversion at all, a DeprecationWarning is raised fwiw, daniel's patch would still cause this deprecation warning from |
Gregory, Regarding my patch, the API wouldn't change at all, as the source reads: So "n - len(bytes)" restricts the API to what it was before. But it @pitrou: My patch still passed the float to read (to keep the current |
Le jeudi 28 août 2008 à 19:30 +0000, Gregory P. Smith a écrit :
Ok, I hadn't thought about that. You convinced me. |
The patch looks fine to me as well. |
committed to trunk r66142 |
Gregory, could you merge this into py3k, please? |
Apparently this isn't an issue in py3k, so no worries! :) |
It seems to me that test case will fail on windows and vms platforms. ./python.exe -c 'import os; print "%s" %(os.urandom(1.9))' => |
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: