From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ioannis Kappas Newsgroups: gmane.emacs.bugs Subject: bug#53808: 29.0.50; ansi colorization process could block indefinetly on stray ESC char Date: Sat, 5 Feb 2022 21:47:50 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25880"; mail-complaints-to="usenet@ciao.gmane.io" To: 53808@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 05 22:49:40 2022 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 1nGSw7-0006Zq-Oi for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Feb 2022 22:49:39 +0100 Original-Received: from localhost ([::1]:54560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGSw5-0004pg-Op for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 05 Feb 2022 16:49:37 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGSvW-0004nu-HZ for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 16:49:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41831) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGSvW-0005oI-8Y for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 16:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nGSvW-0000JC-8B for bug-gnu-emacs@gnu.org; Sat, 05 Feb 2022 16:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ioannis Kappas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 05 Feb 2022 21:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53808 X-GNU-PR-Package: emacs Original-Received: via spool by 53808-submit@debbugs.gnu.org id=B53808.16440976881103 (code B ref 53808); Sat, 05 Feb 2022 21:49:02 +0000 Original-Received: (at 53808) by debbugs.gnu.org; 5 Feb 2022 21:48:08 +0000 Original-Received: from localhost ([127.0.0.1]:35728 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGSue-0000Hj-BB for submit@debbugs.gnu.org; Sat, 05 Feb 2022 16:48:08 -0500 Original-Received: from mail-ot1-f53.google.com ([209.85.210.53]:44800) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGSuc-0000GP-Kv for 53808@debbugs.gnu.org; Sat, 05 Feb 2022 16:48:06 -0500 Original-Received: by mail-ot1-f53.google.com with SMTP id s6-20020a0568301e0600b0059ea5472c98so8054811otr.11 for <53808@debbugs.gnu.org>; Sat, 05 Feb 2022 13:48:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=D5I9shY36r/m1w6YNBk9eYMIn/lAg/x0kwv7g8Img9g=; b=QwHoOHotPz0LcKBufRsi7rxYGUQdTx0CJC4HkDoyizVNn0QIFvuD+vwj2JQ5xzvs6k mCXlTZFG9/lEuokE74nlnp5uKNvWUd4wrpR4LBplp74ZfLOPKbGNbx507pgSrTd+aSFu 6cp33oabgNcKSupnJxIQ5GEKIHkxDDnGUV71TRhFGe3mItuwdYNOYtBd9Ue4a/Qc6bm2 r7UYNoZOJqBSdhLi/0iODdti6jH2Jws360danaxNhx/bPLBGiYwAcPV3esHrv7eJ4Zxv 1cs7miTeBYCmUBWKWn8TWN8r88Py+yd5kleKGY45vEn6xurGdTcx8iJSRe+yv9yFvC/7 VmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=D5I9shY36r/m1w6YNBk9eYMIn/lAg/x0kwv7g8Img9g=; b=Fa/HI+IT9tX9Vsgoy4mwPMVvwqkwdIWuaJpvHmSEbYeHrQbjzQLjlgrz+Zn6TVRbAu VjfgE5felXzqiEQhaGz+1nINbJUopjtgPNT2cBwYB7m8Erg6OZp74kXcwUt1Vnk6GLQs ht6x5UaI9UaQWlljzdcBOcDQMVzbR3INR7xzs/ECKiTj9y+fbO/Fy80CjwQ0NC7JXjDg uPbG3ZFyFhNj2oOVHb8a6NhdzpusT2dCfcX0Ytd1nQPv8IBod7mgv+9CyfepYiNVMbX+ qyQVlBrggsx+ABGTpiVskQbTJtsIMKRWC943Q0+rl3+KjQqp8ZRjcLtjvnNVhpt6hB4c rvTg== X-Gm-Message-State: AOAM531Xf1uzbgJ1aI5zHy+ZG3H0CyjXI2fVKyb6A+Cg3ypUanQR7dWS hzxdYB3Dr6roeSSuNDiGMOpPGu74H4Ma3MtnaI9Jpj3j5qY= X-Google-Smtp-Source: ABdhPJy7G8+og2wJKiaPHQlatHDsi9OeTDLu79ez6wP5dXSqdeioiPuVAKVzeokSsyMQmM4H38fjFXmDMid7fg5UCZk= X-Received: by 2002:a05:6830:25c6:: with SMTP id d6mr1899714otu.91.1644097681026; Sat, 05 Feb 2022 13:48:01 -0800 (PST) In-Reply-To: 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" Xref: news.gmane.io gmane.emacs.bugs:226093 Archived-At: (sorry, I sent out the wrong patch, the correct one is modified lisp/ansi-color.el @@ -501,6 +501,20 @@ ansi-color-filter-apply (setcar (cdr context) fragment)) (apply #'concat (nreverse result)))) +(defconst ansi-color--sgr-partial-regex + "\e\\(?:\\[\\|$\\)\\(?:[0-9]+;?\\)*" + "A regexp for locating the beginning of a partial SGR + sequence.") + +(defun ansi-color--sgr-fragment-pos (string start) + "Check if STRING ends with a partial SGR sequence and return +its position or nil otherwise. Start looking in STRING at position START." + (save-match-data + (when (and (string-match ansi-color--sgr-partial-regex string start) + (or (= (match-end 0) 0) + (= (match-end 0) (length string))) ) + (match-beginning 0)))) + (defun ansi-color-apply (string) "Translates SGR control sequences into text properties. Delete all other control sequences without processing them. @@ -549,8 +563,8 @@ ansi-color-apply (put-text-property start (length string) 'font-lock-face face string)) ;; save context, add the remainder of the string to the result - (if (string-match "\033" string start) - (let ((pos (match-beginning 0))) + (if-let ((pos (ansi-color--sgr-fragment-pos string start))) + (progn (setcar (cdr context) (substring string pos)) (push (substring string start pos) result)) (push (substring string start) result)) )