]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid segfaults in Rmail-MIME
authorEli Zaretskii <eliz@gnu.org>
Wed, 9 Oct 2024 13:21:08 +0000 (16:21 +0300)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Oct 2024 17:37:36 +0000 (19:37 +0200)
Rmail-MIME decodes text of email, including removal of
CR characters, but that can segfault if the text of some
MIME part is empty.
* src/coding.c (decode_coding_raw_text):
* lisp/mail/rmailmm.el (rmail-mime-insert-decoded-text): Don't
attempt to decode empty text region.

(cherry picked from commit f520008744b1eb71accded4108888d1f2055402e)

lisp/mail/rmailmm.el
src/coding.c

index a5ce5b65cd7881498d55b242c10d8193fe327394..d86e48e6281731f1feb585e1c2e8665389f5d70a 100644 (file)
@@ -579,11 +579,13 @@ HEADER is a header component of a MIME-entity object (see
               (ignore-errors (base64-decode-region pos (point))))
              ((string= transfer-encoding "quoted-printable")
               (quoted-printable-decode-region pos (point))))))
-    (decode-coding-region
-     pos (point)
-     ;; Use -dos decoding, to remove ^M characters left from base64 or
-     ;; rogue qp-encoded text.
-     (coding-system-change-eol-conversion coding-system 1))
+    ;; If the text is empty, we don't have anything to decode.
+    (and (/= pos (point))
+         (decode-coding-region
+          pos (point)
+          ;; Use -dos decoding, to remove ^M characters left from base64
+          ;; or rogue qp-encoded text.
+          (coding-system-change-eol-conversion coding-system 1)))
     (if (and
         (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))
         (not (eq (coding-system-base coding-system) 'us-ascii)))
index 547fcbb812017b8caa3fd457b369206a42b3d842..cd5a12972e6d5cef866fdae5b582c36ff73ac32f 100644 (file)
@@ -5270,7 +5270,9 @@ decode_coding_raw_text (struct coding_system *coding)
   coding->chars_at_source = 1;
   coding->consumed_char = coding->src_chars;
   coding->consumed = coding->src_bytes;
-  if (eol_dos && coding->source[coding->src_bytes - 1] == '\r')
+  if (eol_dos
+      && coding->src_bytes > 0 /* empty source text? */
+      && coding->source[coding->src_bytes - 1] == '\r')
     {
       coding->consumed_char--;
       coding->consumed--;