GNU bug report logs - #56271
lisp/progmodes/python.el; unmatched quotes cause infinite loop freezing emacs

Previous Next

Package: emacs;

Reported by: Tom Gillespie <tgbugs <at> gmail.com>

Date: Tue, 28 Jun 2022 01:52:01 UTC

Severity: normal

Tags: patch

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56271 in the body.
You can then email your comments to 56271 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#56271; Package emacs. (Tue, 28 Jun 2022 01:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tom Gillespie <tgbugs <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 28 Jun 2022 01:52:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tom Gillespie <tgbugs <at> gmail.com>
To: Emacs Bug Report <bug-gnu-emacs <at> gnu.org>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 54996 <at> debbugs.gnu.org
Subject: lisp/progmodes/python.el; unmatched quotes cause infinite loop
 freezing emacs
Date: Mon, 27 Jun 2022 18:51:21 -0700
Using git bisect shows 85db21b94b23b4701930892d1eecc9a1167ed968 is the
source of this issue, all commits following it on master show the same
issue. Reverting that commit fixes the issue.

While editing python files if a single quote occurs in the file during
the course of editing then emacs will enter an infinite loop. The
exact location of the single quote is important, but the pattern that
triggers it happens frequently in python files.

You can get a traceback pinpointing the issue by sending SIGUSR2 to
the hung emacs process.

Below is a minimal python file that will trigger the issue.
Run with emacs -Q evil-python-file.py
#+begin_verbatim
def
    =''
 '
""""""
 # there must be at least one space on this line, comment not needed
''
#+end_verbatim

The full pattern that causes the issue is something like the following.

#+begin_verbatim
<keyword>
<exactly-python-indent-offset-number-of-spaces>=<zero-or-more-not-quotes>''
<at-least-one-space>'
<zero-or-more-lines-with-any-contents-except-single-quote-marks*>
<zero-or-more-spaces><triple-double-quote-string><any-but-single-quote>
<at-least-one-space><any-but-single-quote>
<single-quote-string>
#+end_verbatim

Any keyword should work I have tested with class, def, and with.

The zero or more lines at any indentation can also have single quote
marks that are paired, but there is some weirdness when you have 4 on
a line that makes it possible to avoid the issue.

I can fix the issue by reverting to the cl-assert pattern using unless
to raise an error (unless (>= string-start last-string-end) (error
"oops")) and running the code after that unconditionally. This
prevents jit-lock from trying to run infinitely on a malformed buffer.

That said, this may simply reintroduce bug#54996, and the change
unmasked some other issue with what is going on during the call to
jit-lock-function which needed that error to be throw by cl-assert to
avoid infinite loops/retries.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56271; Package emacs. (Wed, 29 Jun 2022 02:47:01 GMT) Full text and rfc822 format available.

Message #8 received at 56271 <at> debbugs.gnu.org (full text, mbox):

From: Tom Gillespie <tgbugs <at> gmail.com>
To: 56271 <at> debbugs.gnu.org
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: lisp/progmodes/python.el; unmatched quotes cause infinite loop
 freezing emacs
Date: Tue, 28 Jun 2022 19:45:58 -0700
[Message part 1 (text/plain, inline)]
I was able to hunt down the issue.

The problem is in python-nav-end-of-block where there is an implicit
assumption that python-nav-end-of-statement always makes forward
progress, which is violated when the buffer contains e.g. a single
quote.

I have attached a patch the resolves this issue but there may be other
lurking issues due to the removal of cl-assert because there are now
all sorts of code paths that will run that never ran before because
they would hit that assertion and bail out, usually all the way back
to the top.
[0001-lisp-progmodes-python.el-python-nav-end-of-block-pre.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56271; Package emacs. (Wed, 29 Jun 2022 03:01:02 GMT) Full text and rfc822 format available.

Message #11 received at 56271 <at> debbugs.gnu.org (full text, mbox):

From: Tom Gillespie <tgbugs <at> gmail.com>
To: 56271 <at> debbugs.gnu.org
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: lisp/progmodes/python.el; unmatched quotes cause infinite loop
 freezing emacs
Date: Tue, 28 Jun 2022 20:00:24 -0700
[Message part 1 (text/plain, inline)]
Patch to add a test using the evil file as an example.
[0001-test-lisp-progmodes-python-tests.el-add-test-for-nav.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56271; Package emacs. (Wed, 29 Jun 2022 10:15:02 GMT) Full text and rfc822 format available.

Message #14 received at 56271 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tom Gillespie <tgbugs <at> gmail.com>
Cc: 56271 <at> debbugs.gnu.org
Subject: Re: lisp/progmodes/python.el; unmatched quotes cause infinite loop
 freezing emacs
Date: Wed, 29 Jun 2022 12:14:06 +0200
Tom Gillespie <tgbugs <at> gmail.com> writes:

> I have attached a patch the resolves this issue but there may be other
> lurking issues due to the removal of cl-assert because there are now
> all sorts of code paths that will run that never ran before because
> they would hit that assertion and bail out, usually all the way back
> to the top.

Tom Gillespie <tgbugs <at> gmail.com> writes:

> Patch to add a test using the evil file as an example.

Thanks; pushed to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 29 Jun 2022 14:56:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56271; Package emacs. (Mon, 05 Sep 2022 19:35:02 GMT) Full text and rfc822 format available.

Message #19 received at 56271 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Tom Gillespie <tgbugs <at> gmail.com>
Cc: 56271 <at> debbugs.gnu.org
Subject: Re: bug#56271: lisp/progmodes/python.el; unmatched quotes cause
 infinite loop freezing emacs
Date: Mon, 05 Sep 2022 21:34:49 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Thanks; pushed to Emacs 29.

But then I apparently forgot to close this bug report, so I'm doing that
now.




bug marked as fixed in version 29.1, send any further explanations to 56271 <at> debbugs.gnu.org and Tom Gillespie <tgbugs <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 05 Sep 2022 19:36:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 04 Oct 2022 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 204 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.