From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#61514: 30.0.50; sadistically long xml line hangs emacs Date: Mon, 20 Feb 2023 14:19:18 +0200 Message-ID: <831qmkwmux.fsf@gnu.org> References: <87lel0c65v.fsf@everybody.org> <838rgvymcd.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15270"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mah@everybody.org, 61514@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 20 13:20:19 2023 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 1pU59W-0003ia-3R for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 Feb 2023 13:20:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pU59N-0004VD-39; Mon, 20 Feb 2023 07:20:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pU59K-0004Ul-CM for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 07:20:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pU59G-0002Qx-NP for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 07:20:06 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pU59G-0006uj-Ir for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 07:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Feb 2023 12:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61514 X-GNU-PR-Package: emacs Original-Received: via spool by 61514-submit@debbugs.gnu.org id=B61514.167689555826515 (code B ref 61514); Mon, 20 Feb 2023 12:20:02 +0000 Original-Received: (at 61514) by debbugs.gnu.org; 20 Feb 2023 12:19:18 +0000 Original-Received: from localhost ([127.0.0.1]:50798 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pU58Y-0006ta-AH for submit@debbugs.gnu.org; Mon, 20 Feb 2023 07:19:18 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41490) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pU58V-0006tL-QM for 61514@debbugs.gnu.org; Mon, 20 Feb 2023 07:19:17 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pU58Q-0002JX-BP; Mon, 20 Feb 2023 07:19:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=GNM0GAddUPYkXc74TXn7a7IHa1bXOanQ7akkjaDD2gI=; b=qibNNwGWYWaV U4tKvz8T4rAE8oEPaRXBKSz9LhbYYcadOGzQEYApggKsWer0qDo/N8lvReQsPtylr8OOhygb0fH1Y mGSi3pxh96OftmFsMQNidTBWiwNJt5d3PHtHcZ4y20tPw7hHD0oaj4Fd+bvaABrWH/6CfdXZnoVwA aJ5CFzLHdathCbXsTF27wn0umgnqgSngZfF5mMkNCE4IKvQF09SE7HbHKcY9C/rAOpEgbCQktMP1m XICVWwOCRwKqn9tU9nWFiDdRTuS27LJ7sLdHvy0wMhRsONcpzkQigijxjPHzrOosDX0YBSG1iV1oQ YNcanSH0CFBVgsuhP4q4Ew==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pU58P-0000Gi-OI; Mon, 20 Feb 2023 07:19:10 -0500 In-Reply-To: (message from Stefan Monnier on Sun, 19 Feb 2023 18:48:43 -0500) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256148 Archived-At: > From: Stefan Monnier > Cc: "Mark A. Hershberger" , 61514@debbugs.gnu.org > Date: Sun, 19 Feb 2023 18:48:43 -0500 > > > The problem is in the combination of nxml-mode and some subtle > > bug/misfeature in our regexp routines. Specifically, when we overflow > > the fail stack, we fail to recover in this case, and seem to infloop > > inside re_match_2_internal, or maybe recover very inefficiently (I > > waited for almost 1 hour before giving up). The call which causes the > > loop is in xmltok.el, in the indicated line: > > > > (defun xmltok-scan-attributes () > > (let ((recovering nil) > > (atts-needing-normalization nil)) > > (while (cond ((or (looking-at (xmltok-attribute regexp)) > > ;; use non-greedy group > > (when (looking-at (concat "[^<>\n]+?" <<<<<<<<<<<<<<<<< > > (xmltok-attribute regexp))) > > (unless recovering > > (xmltok-add-error "Malformed attribute" > > (point) > > (save-excursion > > (goto-char (xmltok-attribute start > > name)) > > (skip-chars-backward "\r\n\t ") > > (point)))) > > t)) > > > > The regexp that causes this is as follows: > > > > "[^<>\n]+?\\(\\(?:\\(xmlns\\)\\|[_[:alpha:]][-._[:alnum:]]*\\)\\(:[_[:alpha:]][-._[:alnum:]]*\\)?\\)[ \r\t\n]*=\\(?:[ \r\t\n]*\\('[^<'&\r\n\t]*\\([&\r\n\t][^<']*\\)?'\\|\"[^<\"&\r\n\t]*\\([&\r\n\t][^<\"]*\\)?\"\\)\\(?:\\([ \r\t\n]*>\\)\\|\\(?:\\([ \r\t\n]*/\\)\\(>\\)?\\)\\|\\([ \r\t\n]+\\)\\)\\)?" > > IIUC the above describes the code where we're stuck inf-looping inside > `looking-at`? Not inflooping, but very slowly backtracking, or so it seems. > Is it the same place where the regexp-stack overflow happens (and with > the same regexp)? It's (almost) the same place, but not the same regexp. The regexp which causes the stack-overflow message (which is emitted from set-auto-mode, before entering redisplay) is this: "\\(\\(?:\\(xmlns\\)\\|[_[:alpha:]][-._[:alnum:]]*\\)\\(:[_[:alpha:]][-._[:alnum:]]*\\)?\\)[ \r\t\n]*=\\(?:[ \r\t\n]*\\('[^<'&\r\n\t]*\\([&\r\n\t][^<']*\\)?'\\|\"[^<\"&\r\n\t]*\\([&\r\n\t][^<\"]*\\)?\"\\)\\(?:\\([ \r\t\n]*>\\)\\|\\(?:\\([ \r\t\n]*/\\)\\(>\\)?\\)\\|\\([ \r\t\n]+\\)\\)\\)?" As you can see, the prepended "[^<>\n]+?" in the regexp which "hangs" makes all the difference. So the looking-at which fails reasonably quickly is the first call to looking-at above, whereas the one the "hangs" is the second one. Maybe this points out a way out of this misery?