1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

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))))
((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)))

View 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--;