]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid regexp overflow in mm-decode-content-transfer-encoding
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 30 Apr 2022 17:14:35 +0000 (19:14 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 30 Apr 2022 17:14:35 +0000 (19:14 +0200)
* lisp/gnus/mm-bodies.el (mm-decode-content-transfer-encoding):
The base64 may be huge, so avoid backtracking (bug#55195).

lisp/gnus/mm-bodies.el

index 956449dac14f788caf41eeabd197ecf8e3739eaa..9f2f80b4726be65eee976b323fcc1ce83041d6b8 100644 (file)
@@ -191,18 +191,17 @@ If TYPE is `text/plain' CRLF->LF translation may occur."
           ((eq encoding 'base64)
            (base64-decode-region
             (point-min)
-            ;; Some mailers insert whitespace
-            ;; junk at the end which
-            ;; base64-decode-region dislikes.
-            ;; Also remove possible junk which could
-            ;; have been added by mailing list software.
             (save-excursion
+               ;; Some mailers insert whitespace junk at the end which
+              ;; base64-decode-region dislikes.
               (goto-char (point-min))
               (while (re-search-forward "^[\t ]*\r?\n" nil t)
                 (delete-region (match-beginning 0) (match-end 0)))
+              ;; Also ignore junk which could have been added by
+              ;; mailing list software by finding the final line with
+              ;; base64 text.
               (goto-char (point-max))
-              (when (re-search-backward "^[\t ]*[A-Za-z0-9+/]+=*[\t ]*$"
-                                        nil t)
+              (when (re-search-backward "[A-Za-z0-9+/]{3,3}=?[\t ]*$" nil t)
                 (forward-line))
               (point))))
           ((memq encoding '(nil 7bit 8bit binary))