[New-bugs-announce] [issue32329] PYTHONHASHSEED=0 python3 -R should enable hash randomization

STINNER Victor report at bugs.python.org
Thu Dec 14 18:11:20 EST 2017


New submission from STINNER Victor <victor.stinner at gmail.com>:

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 at apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner at apu$ PYTHONHASHSEED=0 python3 -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner at 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 at apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(sys.flags.hash_randomization)'
1
vstinner at apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner at apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518
vstinner at apu$ PYTHONHASHSEED=0 python3 -R -c 'import sys; print(hash("abc"))'
4596069200710135518

I expect that -R enables hash randomization and overrides PYTHONHASHSEED environment variable.

Attached PR fixes these issues and adds an unit test.

----------
messages: 308343
nosy: vstinner
priority: normal
severity: normal
status: open
title: PYTHONHASHSEED=0 python3 -R should enable hash randomization
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32329>
_______________________________________


More information about the New-bugs-announce mailing list