Commit 0209dc1f authored by Antoine Pitrou's avatar Antoine Pitrou

Clarify that hash randomization is on by default

parent a562ed01
...@@ -229,23 +229,22 @@ Miscellaneous options ...@@ -229,23 +229,22 @@ Miscellaneous options
.. cmdoption:: -R .. cmdoption:: -R
Turn on hash randomization, so that the :meth:`__hash__` values of str, bytes Kept for compatibility. On Python 3.3 and greater, hash randomization is
and datetime objects are "salted" with an unpredictable random value. turned on by default.
Although they remain constant within an individual Python process, they are
not predictable between repeated invocations of Python. On previous versions of Python, this option turns on hash randomization,
so that the :meth:`__hash__` values of str, bytes and datetime
This is intended to provide protection against a denial-of-service caused by are "salted" with an unpredictable random value. Although they remain
carefully-chosen inputs that exploit the worst case performance of a dict constant within an individual Python process, they are not predictable
construction, O(n^2) complexity. See between repeated invocations of Python.
Hash randomization is intended to provide protection against a
denial-of-service caused by carefully-chosen inputs that exploit the worst
case performance of a dict construction, O(n^2) complexity. See
http://www.ocert.org/advisories/ocert-2011-003.html for details. http://www.ocert.org/advisories/ocert-2011-003.html for details.
Changing hash values affects the order in which keys are retrieved from a :envvar:`PYTHONHASHSEED` allows you to set a fixed value for the hash
dict. Although Python has never made guarantees about this ordering (and it seed secret.
typically varies between 32-bit and 64-bit builds), enough real-world code
implicitly relies on this non-guaranteed behavior that the randomization is
disabled by default.
See also :envvar:`PYTHONHASHSEED`.
.. versionadded:: 3.2.3 .. versionadded:: 3.2.3
...@@ -486,8 +485,8 @@ These environment variables influence Python's behavior. ...@@ -486,8 +485,8 @@ These environment variables influence Python's behavior.
.. envvar:: PYTHONHASHSEED .. envvar:: PYTHONHASHSEED
If this variable is set to ``random``, a random value is used to seed the If this variable is not set or set to ``random``, a random value is used
hashes of str, bytes and datetime objects. to seed the hashes of str, bytes and datetime objects.
If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed
seed for generating the hash() of the types covered by the hash seed for generating the hash() of the types covered by the hash
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment