Avoid segfaults in Rmail-MIME

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.
This commit is contained in:
Eli Zaretskii 2024-10-09 16:21:08 +03:00
parent 6a5c2edd84
commit f520008744
2 changed files with 10 additions and 6 deletions

View file

@ -579,11 +579,13 @@ HEADER is a header component of a MIME-entity object (see
(ignore-errors (base64-decode-region pos (point)))) (ignore-errors (base64-decode-region pos (point))))
((string= transfer-encoding "quoted-printable") ((string= transfer-encoding "quoted-printable")
(quoted-printable-decode-region pos (point)))))) (quoted-printable-decode-region pos (point))))))
(decode-coding-region ;; If the text is empty, we don't have anything to decode.
pos (point) (and (/= pos (point))
;; Use -dos decoding, to remove ^M characters left from base64 or (decode-coding-region
;; rogue qp-encoded text. pos (point)
(coding-system-change-eol-conversion coding-system 1)) ;; 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 (if (and
(or (not rmail-mime-coding-system) (consp rmail-mime-coding-system)) (or (not rmail-mime-coding-system) (consp rmail-mime-coding-system))
(not (eq (coding-system-base coding-system) 'us-ascii))) (not (eq (coding-system-base coding-system) 'us-ascii)))

View file

@ -5270,7 +5270,9 @@ decode_coding_raw_text (struct coding_system *coding)
coding->chars_at_source = 1; coding->chars_at_source = 1;
coding->consumed_char = coding->src_chars; coding->consumed_char = coding->src_chars;
coding->consumed = coding->src_bytes; 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_char--;
coding->consumed--; coding->consumed--;