Subject: bug#28329: 25.2; Eshell: 40M+ output: Stack overflow in regexp matcher

From: Noam Postavsky <[email-masked]>
Date: Sun, 30 Jun 2019 09:45:16 -0400

Pierre Neidhardt <[email-masked]> writes:

> So I never got around reproducing the issue with Gentoo, and soon after
> I dropped Gentoo and moved to Guix, with which I've never been able to
> re-experience this issue, even on massive Eshell buffers (couple of 10M...).
>
> As far as I'm concerned, this could be closed, but maybe another Gentoo
> user out there would be able to tell us more.

Oh yeah, I still have a possible fix sitting in my local repo.
Attaching here for posterity, but I wouldn't want to apply it unless we
actually know that it would help (because it might break legitimate
matches).

>From 7a3bdc88941f90c5506165ddf4b9d12f51ba9ea3 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
Date: Sat, 2 Sep 2017 08:17:48 -0400
Subject: [PATCH] [?] Only match password prompts in part of line (Bug#28329)

* lisp/eshell/esh-mode.el (eshell-password-prompt-regexp): Add
beginning of line anchor, and use {,80} instead of * to restrict
matches in long lines.
---
 lisp/eshell/esh-mode.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index 80844c3a64..9f80700c6a 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -179,7 +179,10 @@ eshell-preoutput-filter-functions
   :group 'eshell-mode)
 
 (defcustom eshell-password-prompt-regexp
-  (format "\\(%s\\)[^:：៖]*[:：៖]\\s *\\'" (regexp-opt password-word-equivalents))
+  ;; Assume prompt will show up near the beginning of a line, this
+  ;; should prevent excessive regexp searches on long lines.
+  (format "^.\\{,80\\}%s[^:：៖]\\{,80\\}[:：៖]\\s-*\\'"
+          (regexp-opt password-word-equivalents))
   "Regexp matching prompts for passwords in the inferior process.
 This is used by `eshell-watch-for-password-prompt'."
   :type 'regexp
-- 
2.11.0