[姆咪] Python int/str conversions bugfix已回收
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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.198.173.41 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1663081070.A.363.html