diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-28 09:17:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-28 09:17:51 (GMT) |
commit | befc956acf8ddeb94f000ed081ddec51315429e5 (patch) | |
tree | cf34b0e10b6959622d7969bb43ad8f4bbb01553f /Modules | |
parent | 68b131d5b674549bb637b366730497714ad11328 (diff) | |
download | cpython-befc956acf8ddeb94f000ed081ddec51315429e5.zip cpython-befc956acf8ddeb94f000ed081ddec51315429e5.tar.gz cpython-befc956acf8ddeb94f000ed081ddec51315429e5.tar.bz2 |
[3.6] bpo-31478: Fix an assertion failure in random.seed() in case a seed has a bad __abs__() method. (GH-3596) (#3794)
(cherry picked from commit d780b2d588e68bd7047ef5d1f04e36da38b7a350)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_randommodule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index d006aeb..769084f 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -259,8 +259,11 @@ random_seed(RandomObject *self, PyObject *args) * So: if the arg is a PyLong, use its absolute value. * Otherwise use its hash value, cast to unsigned. */ - if (PyLong_Check(arg)) - n = PyNumber_Absolute(arg); + if (PyLong_Check(arg)) { + /* Calling int.__abs__() prevents calling arg.__abs__(), which might + return an invalid value. See issue #31478. */ + n = PyLong_Type.tp_as_number->nb_absolute(arg); + } else { Py_hash_t hash = PyObject_Hash(arg); if (hash == -1) |