unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tom Gillespie <tgbugs@gmail.com>
To: 56271@debbugs.gnu.org
Cc: Lars Ingebrigtsen <larsi@gnus.org>
Subject: bug#56271: lisp/progmodes/python.el; unmatched quotes cause infinite loop freezing emacs
Date: Tue, 28 Jun 2022 19:45:58 -0700	[thread overview]
Message-ID: <CA+G3_PNpJOkCu0iEdtzd0jTZ0DbBUcLJrS6nMwti8-NW7E0uKQ@mail.gmail.com> (raw)
In-Reply-To: <CA+G3_POGKF-fDfBuxNcc93WSEaaYzAd4FSgk-vKy=tQYOXYtHg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 534 bytes --]

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.

[-- Attachment #2: 0001-lisp-progmodes-python.el-python-nav-end-of-block-pre.patch --]
[-- Type: text/x-patch, Size: 2524 bytes --]

From 0b37e78d633af66d96e49655e3bb8418433a6164 Mon Sep 17 00:00:00 2001
From: Tom Gillespie <tgbugs@gmail.com>
Date: Tue, 28 Jun 2022 19:28:05 -0700
Subject: [PATCH] lisp/progmodes/python.el (python-nav-end-of-block): prevent
 infinite loop

lisp/progmodes/python.el (python-nav-end-of-block): Fix a bad
assumption that python-nav-end-of-statement always makes forward
progress by testing that it actually does. If this check is not made
then it is possible for python-nav-end-of-block to enter an infinite
loop. (bug#56271)
---
 lisp/progmodes/python.el | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e0c937d7ce..16cdf58611 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1636,11 +1636,15 @@ python-nav-end-of-statement
     (while (and (or noend (goto-char (line-end-position)))
                 (not (eobp))
                 (cond ((setq string-start (python-syntax-context 'string))
-                       ;; The assertion can only fail if syntax table
+                       ;; The condition can be nil if syntax table
                        ;; text properties and the `syntax-ppss' cache
                        ;; are somehow out of whack.  This has been
                        ;; observed when using `syntax-ppss' during
                        ;; narrowing.
+                       ;; It can also fail in cases where the buffer is in
+                       ;; the process of being modified, e.g. when creating
+                       ;; a string with `electric-pair-mode' disabled such
+                       ;; that there can be an unmatched single quote
                        (when (>= string-start last-string-end)
                          (goto-char string-start)
                          (if (python-syntax-context 'paren)
@@ -1723,7 +1727,10 @@ python-nav-end-of-block
       (while (and (forward-line 1)
                   (not (eobp))
                   (or (and (> (current-indentation) block-indentation)
-                           (or (python-nav-end-of-statement) t))
+                           (let ((start (point)))
+                             (python-nav-end-of-statement)
+                             ;; must move forward otherwise infinite loop
+                             (> (point) start)))
                       (python-info-current-line-comment-p)
                       (python-info-current-line-empty-p))))
       (python-util-forward-comment -1)
-- 
2.35.1


  parent reply	other threads:[~2022-06-29  2:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  1:51 bug#56271: lisp/progmodes/python.el; unmatched quotes cause infinite loop freezing emacs Tom Gillespie
     [not found] ` <87lethroiv.fsf@gnus.org>
     [not found]   ` <CA+G3_POGKF-fDfBuxNcc93WSEaaYzAd4FSgk-vKy=tQYOXYtHg@mail.gmail.com>
2022-06-29  2:45     ` Tom Gillespie [this message]
2022-06-29  3:00       ` Tom Gillespie
2022-06-29 10:14       ` Lars Ingebrigtsen
2022-09-05 19:34         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+G3_PNpJOkCu0iEdtzd0jTZ0DbBUcLJrS6nMwti8-NW7E0uKQ@mail.gmail.com \
    --to=tgbugs@gmail.com \
    --cc=56271@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).