Subject: Re: bug#13802: stack overflow in mm-add-meta-html-tag

From: Lars Ingebrigtsen <[email-masked]>
Date: Thu, 30 Jan 2014 16:38:49 -0800

Juri Linkov <[email-masked]> writes:

>> I see a "Stack overflow in regexp matcher" error traceable back to
>> lisp/gnus/mm-decode.el func ‘mm-add-meta-html-tag’ fragment:
>>
>>   (re-search-forward "\
>>   <meta\\s-+http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']\
>>   text/\\(\\sw+\\)\\(?:\;\\s-*charset=\\(.+\\)\\)?[\"'][^>]*>" nil t)
>>
>> To allow the user (not me) to continue, i kludged the form to be:
>>
>>   (ignore-errors
>>     (re-search-forward "..." nil t))
>>
>> that is, wrapping w/ ‘ignore-errors’.  Is there a better solution?
>
> `sgml-html-meta-auto-coding-function' uses a similar regexp
> that doesn't fail with stack overflow.  You could get some ideas
> from this regexp and sync the regexp in `mm-add-meta-html-tag' with it.

I've adapted the regexp from that function in the patch below, but since
I don't have a test case, I'm not really sure about committing it.

Thien-Thi, could you post the message that triggers this error, or the
relevant bits of it?

diff --git a/lisp/mm-decode.el b/lisp/mm-decode.el
index 17c8fb1..eaf9de4 100644
--- a/lisp/mm-decode.el
+++ b/lisp/mm-decode.el
@@ -1405,9 +1405,7 @@ Return t if meta tag is added or replaced."
 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">" charset))
       (let ((case-fold-search t))
 	(goto-char (point-min))
-	(if (re-search-forward "\
-<meta\\s-+http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']\
-text/\\(\\sw+\\)\\(?:\;\\s-*charset=\\([^\"'>]+\\)\\)?[^>]*>" nil t)
+	(if (re-search-forward "<meta\\s-+\\http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']text/\\(\\sw+\\)\\(?:;\\s-*?charset=[\"']?\\(.+?\\)\\)[\"'\\s-/>]" nil t)
 	    (if (and (not force-charset)
 		     (match-beginning 2)
 		     (string-match "\\`html\\'" (match-string 1)))

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