From 159d8f7a0afec26382d570ad95a1a3b2559f642d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 1 May 2022 10:20:07 +0200 Subject: [PATCH] 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. --- lisp/gnus/mm-bodies.el | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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. -- 2.39.2