From: Lars Ingebrigtsen Date: Sun, 1 May 2022 08:20:07 +0000 (+0200) Subject: Fix the mm-decode-content-transfer-encoding overflow better X-Git-Tag: emacs-29.0.90~1931^2~161 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=159d8f7a0afec26382d570ad95a1a3b2559f642d;p=emacs.git Fix the mm-decode-content-transfer-encoding overflow better * lisp/gnus/mm-bodies.el (mm-decode-content-transfer-encoding): Use it. (mm-base64-line-p): New function. --- diff --git a/lisp/gnus/mm-bodies.el b/lisp/gnus/mm-bodies.el index 9f2f80b4726..0d4237a64c9 100644 --- a/lisp/gnus/mm-bodies.el +++ b/lisp/gnus/mm-bodies.el @@ -201,8 +201,11 @@ If TYPE is `text/plain' CRLF->LF translation may occur." ;; mailing list software by finding the final line with ;; base64 text. (goto-char (point-max)) - (when (re-search-backward "[A-Za-z0-9+/]{3,3}=?[\t ]*$" nil t) - (forward-line)) + (beginning-of-line) + (while (and (not (mm-base64-line-p)) + (not (bobp))) + (forward-line -1)) + (forward-line 1) (point)))) ((memq encoding '(nil 7bit 8bit binary)) ;; Do nothing. @@ -235,6 +238,18 @@ If TYPE is `text/plain' CRLF->LF translation may occur." (while (search-forward "\r\n" nil t) (replace-match "\n" t t))))) +(defun mm-base64-line-p () + "Say whether the current line is base64." + ;; This is coded in this way to avoid using regexps that may + ;; overflow -- a base64 line may be megabytes long. + (save-excursion + (beginning-of-line) + (skip-chars-forward " \t") + (skip-chars-forward "A-Za-z0-9+") + (skip-chars-forward "=") + (skip-chars-forward " \t") + (eolp))) + (defun mm-decode-body (charset &optional encoding type) "Decode the current article that has been encoded with ENCODING to CHARSET. ENCODING is a MIME content transfer encoding.