-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
PYTHONHASHSEED=0 python3 -R should enable hash randomization #76510
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
Comments
Python pretends that hash randomization is always enabled, but it's not: $ PYTHONHASHSEED=0 python3 -c 'import sys; print(sys.flags.hash_randomization)'
1
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner@apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518 => sys.flags.hash_randomization must be zero Moreover, the -R flag is always ignored, it's not possible to override the PYTHONHASHSEED environment variable: vstinner@apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(sys.flags.hash_randomization)' I expect that -R enables hash randomization and overrides PYTHONHASHSEED environment variable. Attached PR fixes these issues and adds an unit test. |
"PYTHONHASHSEED=0 python3 -R" now enables hash randomization on master (Python 3.7), I also fixed the sys.flags.hash_randomization value when using PYTHONHASHSEED=0. I chose to not modify the behaviour of the -R option in Python 3.6. I dislike having to document a behaviour change in a minor Python version (3.6.x). I only fixed the value of sys.flags.hash_randomization in Python 3.6. |
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: