[姆咪] Python int/str conversions bugfix

楼主: int0x80 (请逐项修改)   2022-09-13 22:57:44
Python 在最近无预警的更新了“修正”:
https://docs.python.org/3.10/whatsnew/changelog.html#security
现在在将 int 转成 str 时(例如在 print 时)会因为数字太长而错误
>>> import math
>>> math.factorial(1559)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300) for integer string conversion
这个安全漏洞的根本原因是 Python 在做 int 跟 str 转换时
如果是以 10 等非 2 的次方为底
那 Python 用的算法复杂度会是 O(n^2)
所以有可能会造成 DoS
可以用 sys.set_int_max_str_digits(0) 来取消上限
因为目的是修正安全漏洞,所以事前没有公开
有些套件会因为这个修正而坏掉
所以有一些人在抱怨
https://github.com/python/cpython/issues/95778
https://discuss.python.org/t/18889
https://news.ycombinator.com/item?id=32753235

Links booklink

Contact Us: admin [ a t ] ucptt.com