From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#22149: 24.4; gdb stack overflow in regexp matcher Date: Fri, 13 Mar 2020 19:58:23 +0100 Message-ID: References: Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_7349273C-9C8F-479E-9149-15183FB80245" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="86807"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Andreas Schwab , Cheng-An Yang , 22149@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 13 20:03:45 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jCpaz-000MSL-0J for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Mar 2020 20:03:45 +0100 Original-Received: from localhost ([::1]:35778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCpay-00039l-13 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Mar 2020 15:03:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51239) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCpWR-0007JY-Uq for bug-gnu-emacs@gnu.org; Fri, 13 Mar 2020 14:59:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCpWQ-0001So-IQ for bug-gnu-emacs@gnu.org; Fri, 13 Mar 2020 14:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54264) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jCpWP-0001S6-Og for bug-gnu-emacs@gnu.org; Fri, 13 Mar 2020 14:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jCpWP-0003h4-Jz for bug-gnu-emacs@gnu.org; Fri, 13 Mar 2020 14:59:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Mar 2020 18:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22149 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 22149-submit@debbugs.gnu.org id=B22149.158412591114158 (code B ref 22149); Fri, 13 Mar 2020 18:59:01 +0000 Original-Received: (at 22149) by debbugs.gnu.org; 13 Mar 2020 18:58:31 +0000 Original-Received: from localhost ([127.0.0.1]:60237 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jCpVv-0003gI-BR for submit@debbugs.gnu.org; Fri, 13 Mar 2020 14:58:31 -0400 Original-Received: from mail231c50.megamailservers.eu ([91.136.10.241]:54146 helo=mail37c50.megamailservers.eu) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jCpVs-0003g8-9J for 22149@debbugs.gnu.org; Fri, 13 Mar 2020 14:58:29 -0400 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1584125906; bh=2u3aBjAZ6suPQP0vTspgGq7G7t6W1RPd0I1IyLuHLP8=; h=From:Subject:Date:Cc:To:From; b=rBmtpmt5BxWFzIkQ5oBtRl/ZP4kvu42HaWVxITFVx2k8W9RvLO1xSoebamVzTEn7N 4yvJk03Kb/1JPrCdaYzftjo39hpkc4OzwG47DphXp0Imd2z1fOkdvOTl0SteGVAW+m RNGZB8KtRhVwzVLP5QVMknzvnv3PYQOJagu0Hf3o= Feedback-ID: mattiase@acm.or Original-Received: from stanniol.lan (c-6f4fe655.032-75-73746f71.bbcust.telenor.se [85.230.79.111]) (authenticated bits=0) by mail37c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id 02DIwNkV014626; Fri, 13 Mar 2020 18:58:25 +0000 X-Mailer: Apple Mail (2.3445.104.11) X-CTCH-RefID: str=0001.0A782F21.5E6BD7C1.006B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=bJNo382Z c=1 sm=1 tr=0 a=fHaj9vQUQVKQ4sUldAaXuQ==:117 a=fHaj9vQUQVKQ4sUldAaXuQ==:17 a=M51BFTxLslgA:10 a=g3ORMXTKS-KqPaF8PP8A:9 a=CjuIK1q_8ugA:10 a=iRIPyQ-nBtdXvEJBRekA:9 a=B2y7HmGcmWMA:10 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177293 Archived-At: --Apple-Mail=_7349273C-9C8F-479E-9149-15183FB80245 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This was a while ago, but the effect can still be observed in current = master (28.0.50). The exact reproduction no longer works but it's = probably just a quantitive change; perhaps the regexp stack has become = bigger. Simplified, and with some character renaming for clarity, the test case = is essentially (string-match (rx "t" (* (or (not (any "bq")) (: "b" nonl))) "q") (concat "t" (make-string 160000 ?a))) where the number 160000 can be lowered a bit to avoid the stack = overflow. One way of dodging the error regardless of string size is to swap the = two 'or' operands, so that the (: "b" nonl) part, which usually fails, = is attempted first. This is because the NFA matcher implements a kind of = TCO: no backtrack point on the stack is needed for the last or-clause. In fact, Noam's proposed workaround, equivalent to (string-match (rx "t" (* (or "bq" (not "b"))) "q") (concat "t" (make-string 160000 ?a))) works precisely for this reason -- swapping the or-clauses here gives a = stack overflow again. What about this patch for Emacs 27? --Apple-Mail=_7349273C-9C8F-479E-9149-15183FB80245 Content-Disposition: attachment; filename=0001-Avoid-regexp-stack-overflow-in-GDB-string-matching-b.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Avoid-regexp-stack-overflow-in-GDB-string-matching-b.patch" Content-Transfer-Encoding: quoted-printable =46rom=2098db2fe313f869fcd146e4accc9e8cb2296468a2=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Fri,=2013=20Mar=202020=2019:51:02=20+0100=0A= Subject:=20[PATCH]=20Avoid=20regexp=20stack=20overflow=20in=20GDB=20= string=20matching=0A=20(bug#22149)=0A=0A*=20lisp/progmodes/gdb-mi.el=20= (gdb--string-regexp):=0ASwap=20the=20or-clauses=20so=20that=20the=20= rarely=20matching=20one=20comes=20first.=0AThis=20avoids=20a=20build-up=20= of=20backtrack=20points=20on=20the=20regexp=20stack.=0A---=0A=20= lisp/progmodes/gdb-mi.el=20|=205=20++++-=0A=201=20file=20changed,=204=20= insertions(+),=201=20deletion(-)=0A=0Adiff=20--git=20= a/lisp/progmodes/gdb-mi.el=20b/lisp/progmodes/gdb-mi.el=0Aindex=20= e785acd284..5533aa000d=20100644=0A---=20a/lisp/progmodes/gdb-mi.el=0A+++=20= b/lisp/progmodes/gdb-mi.el=0A@@=20-1035,7=20+1035,10=20@@=20= gdb-create-define-alist=0A=20=0A=20(declare-function=20tooltip-show=20= "tooltip"=20(text=20&optional=20use-echo-area))=0A=20=0A-(defconst=20= gdb--string-regexp=20"\"\\(?:[^\\\"]\\|\\\\.\\)*\"")=0A+(defconst=20= gdb--string-regexp=20(rx=20"\""=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(*=20(or=20= (seq=20"\\"=20nonl)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (not=20(any=20"\"\\"))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20"\""))=0A=20=0A=20= (defun=20gdb-tooltip-print=20(expr)=0A=20=20=20(with-current-buffer=20= (gdb-get-buffer=20'gdb-partial-output-buffer)=0A--=20=0A2.21.1=20(Apple=20= Git-122.3)=0A=0A= --Apple-Mail=_7349273C-9C8F-479E-9149-15183FB80245--