From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Wellons Newsgroups: gmane.emacs.bugs Subject: bug#38753: 27.0.60; cl--random-state uncontrolled growth due to bignums Date: Thu, 26 Dec 2019 12:12:07 -0500 Message-ID: <20191226171207.cepft7cjmmbuow6o@nullprogram.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="60949"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20170113 (1.7.2) To: 38753@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Dec 26 18:13:13 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ikWhC-000Ffi-AG for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Dec 2019 18:13:10 +0100 Original-Received: from localhost ([::1]:55304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikWhB-0001qD-5f for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Dec 2019 12:13:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48434) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikWh6-0001ot-5Q for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:13:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikWh5-0000TR-0m for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:13:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50179) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ikWh4-0000TF-Tb for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:13:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ikWh4-00068c-Oa for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:13:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Christopher Wellons Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Dec 2019 17:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 38753 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.157738033423537 (code B ref -1); Thu, 26 Dec 2019 17:13:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Dec 2019 17:12:14 +0000 Original-Received: from localhost ([127.0.0.1]:56152 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ikWgH-00067Y-Tr for submit@debbugs.gnu.org; Thu, 26 Dec 2019 12:12:14 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:48124) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ikWgF-00067Q-Fi for submit@debbugs.gnu.org; Thu, 26 Dec 2019 12:12:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48143) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikWgE-0001n0-E8 for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:12:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikWgD-0000Ax-EE for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:12:10 -0500 Original-Received: from mail.nullprogram.com ([192.241.191.137]:52338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikWgD-0000Aj-BK for bug-gnu-emacs@gnu.org; Thu, 26 Dec 2019 12:12:09 -0500 Original-Received: from nullprogram.com (localhost [127.0.0.1]) by mail.nullprogram.com (Postfix) with ESMTPS id 4973FC5332 for ; Thu, 26 Dec 2019 12:12:08 -0500 (EST) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:173786 Archived-At: The cl-random generator was not written for bignums, so it misbehaves in Emacs 27. After generating a few million numbers from any particular state, it will only signal "Arithmetic overflow error". The generator relies on fixnums wrapping via two's complement. In Emacs 27, fixnums turn into bignums rather than wrap, so the state grows until reaching the bignum limit, then breaks. The cl-random function is a lagged Fibonacci generator. The output is the difference of two integers at special "taps" in the state vector, and one tap is replaced with the output. The output is properly truncated using logand, but state update is not, and it soon fills with growing bignums. The fix is trivial: Move the logand truncation so that it applies to both the output and the state update. The truncated bits are never used so the output of the generator remains unchanged. diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index 7e9d8fe870..2e0b37c14d 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -469,7 +469,7 @@ cl-random (while (< (setq i (1+ i)) 200) (cl-random 2 state)))) (let* ((i (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-i state))) (j (cl-callf (lambda (x) (% (1+ x) 55)) (cl--random-state-j state))) - (n (logand 8388607 (aset vec i (- (aref vec i) (aref vec j)))))) + (n (aset vec i (logand 8388607 (- (aref vec i) (aref vec j)))))) (if (integerp lim) (if (<= lim 512) (% n lim) (if (> lim 8388607) (setq n (+ (ash n 9) (cl-random 512 state))))