From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61514: 30.0.50; sadistically long xml line hangs emacs Date: Mon, 20 Feb 2023 09:59:30 -0500 Message-ID: References: <87lel0c65v.fsf@everybody.org> <838rgvymcd.fsf@gnu.org> <831qmkwmux.fsf@gnu.org> <83cz64v3v7.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18751"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: mah@everybody.org, 61514@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 20 16:00:23 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 1pU7eP-0004gm-W9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 Feb 2023 16:00:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pU7eB-00080u-Nx; Mon, 20 Feb 2023 10:00:08 -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 1pU7e7-0007zo-4Z for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 10:00:03 -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 1pU7e6-000725-Kb for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 10:00:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pU7e6-0008AY-9r for bug-gnu-emacs@gnu.org; Mon, 20 Feb 2023 10:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Feb 2023 15:00: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.167690518231341 (code B ref 61514); Mon, 20 Feb 2023 15:00:02 +0000 Original-Received: (at 61514) by debbugs.gnu.org; 20 Feb 2023 14:59:42 +0000 Original-Received: from localhost ([127.0.0.1]:53254 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pU7dl-00089R-W4 for submit@debbugs.gnu.org; Mon, 20 Feb 2023 09:59:42 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:49633) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pU7di-00089A-S6 for 61514@debbugs.gnu.org; Mon, 20 Feb 2023 09:59:40 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 295F2807CB; Mon, 20 Feb 2023 09:59:33 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 878F380240; Mon, 20 Feb 2023 09:59:31 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1676905171; bh=+kh96zdVs8rW65u6Nof4oTijzIVSJIeUWICtGyPomhA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bVOob67jeMgMNwB8IuM9HjTTnoQ7kahfqBGAiQjmFz7hhIGIboSKwjo4bFCbZOSLc 5yDwF7OqwxMoyLUFkoPGix6d7HkxXBDbZ+AoxK9OU/b5bXQfIVpsUaalQdpcKI5c5s GSy2ya0cFTE4Mbrnd8L6Pu5v1aYG9jcPzlmOs0quBRD19ThHnGAH9ROrduYJESWZPU B6wAEjgg7u0jqrLVzgBfBvigbR6Fs0oFtvZfJEcsZxXEZ4NX2O3TMDWbMnkECR6dqi cwzjhUrlzrhxee71piDxiUgFDET8UVYV5DpUi+YYW+XDZbx9SoXlfKqQAwRxglgdVh qNaiIAUN53OyQ== Original-Received: from pastel (unknown [216.154.34.24]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 6259D123197; Mon, 20 Feb 2023 09:59:31 -0500 (EST) In-Reply-To: <83cz64v3v7.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 20 Feb 2023 15:54:52 +0200") 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:256189 Archived-At: Eli Zaretskii [2023-02-20 15:54:52] wrote: >> From: Stefan Monnier >> Cc: mah@everybody.org, 61514@debbugs.gnu.org >> Date: Mon, 20 Feb 2023 08:19:26 -0500 >> >> > "\\(\\(?:\\(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. >> >> Yes, it makes a lot of sense now. >> >> > Maybe this points out a way out of this misery? >> >> I think it does. E.g. there's a chance that using "[^<>\n]+?\\<" >> instead of "[^<>\n]+?" avoids the hang > > It does, thanks. > >> (not sure if it's the right thing to do for all the regexp that can >> be returned by `xmltok-attribute`, tho). > > How would we go about finding out? Because other than that, changing > the regexp solves this nasty problem, and all the tests in > test/lisp/nxml/ still pass. I did find out: we'll always get the same regexp hre, so it's OK. It turns out that (xmltok-attribute regexp) doesn't mean to return "the something of `regexp`" but to return the "the regexp named `xmltok-attribute`". `xmltok-attribute` is a funny macro built by `xmltok-defregexp`. >> And for the stack overflow I haven't yet found its origin. > > Not sure what is the mystery here. AFAIU, we look for the closing > ">", don't find it, and then start looking for fewer and fewer non-'>' > characters followed by '>'. Isn't that what happens here? Right, but the stack overflows always come from repetitions where our `mutually_exclusive_p` test fails. Let's see: \\(\\(?:\\(xmlns\\)\\|[_[:alpha:]][-._[:alnum:]]*\\)\\(:[_[:alpha:]][-._[:alnum:]]*\\)?\\)[ \r\t\n]*= The first two `*` should be non-backtracking because they repeat [-._[:alnum:]] which is mutually-exclusive with what follows (either `:` or whitespace, or `=`). Similarly the third `*` should be non-backtracking because its body can't match the `=` that must follow. \\(?:[\s\r\t\n]* there aren't enough whitespaces so even if this can backtrack it shouldn't be the source of our current problems. \\('[^<'&\r\n\t]*\\([&\r\n\t][^<']*\\)?' Neither `*` here should backtrack. \\|\"[^<\"&\r\n\t]*\\([&\r\n\t][^<\"]*\\)?\"\\) Same here. \\(?:\\([ \r\t\n]*>\\)\\|\\(?:\\([ \r\t\n]*/\\)\\(>\\)?\\)\\|\\([ \r\t\n]+\\)\\)\\)?" And here we're back to only repeating whitespace. What am I missing? Stefan