aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorPaul Eggert2020-04-20 22:26:30 -0700
committerPaul Eggert2020-04-20 22:31:11 -0700
commitc88a3be8087ad0165415aa87c01f868a7433cb21 (patch)
tree5bba8004c1846653aa514416d31c6b47034df740 /src/coding.c
parent856d9378a49ec9ec1af2ea74fb9309fe4c39cd1d (diff)
downloademacs-c88a3be8087ad0165415aa87c01f868a7433cb21.tar.gz
emacs-c88a3be8087ad0165415aa87c01f868a7433cb21.zip
Fix string-to-multibyte overlong sequence bug
* src/character.h (MULTIBYTE_LENGTH, MULTIBYTE_LENGTH_NO_CHECK): Remove, replacing with ... (multibyte_length): ... this new function. All callers changed. The new function rejects overlong multibyte forms. * test/src/buffer-tests.el (buffer-multibyte-overlong-sequences): New test.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/coding.c b/src/coding.c
index 716b0d99792..34f36d5a86a 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -7670,15 +7670,17 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7670 7670
7671 if (! multibytep) 7671 if (! multibytep)
7672 { 7672 {
7673 int bytes;
7674
7675 if (coding->encoder == encode_coding_raw_text 7673 if (coding->encoder == encode_coding_raw_text
7676 || coding->encoder == encode_coding_ccl) 7674 || coding->encoder == encode_coding_ccl)
7677 c = *src++, pos++; 7675 c = *src++, pos++;
7678 else if ((bytes = MULTIBYTE_LENGTH (src, src_end)) > 0)
7679 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos += bytes;
7680 else 7676 else
7681 c = BYTE8_TO_CHAR (*src), src++, pos++; 7677 {
7678 int bytes = multibyte_length (src, src_end, true, true);
7679 if (0 < bytes)
7680 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos += bytes;
7681 else
7682 c = BYTE8_TO_CHAR (*src), src++, pos++;
7683 }
7682 } 7684 }
7683 else 7685 else
7684 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos++; 7686 c = STRING_CHAR_ADVANCE_NO_UNIFY (src), pos++;
@@ -7727,7 +7729,7 @@ consume_chars (struct coding_system *coding, Lisp_Object translation_table,
7727 for (i = 1; i < to_nchars; i++) 7729 for (i = 1; i < to_nchars; i++)
7728 *buf++ = XFIXNUM (AREF (trans, i)); 7730 *buf++ = XFIXNUM (AREF (trans, i));
7729 for (i = 1; i < from_nchars; i++, pos++) 7731 for (i = 1; i < from_nchars; i++, pos++)
7730 src += MULTIBYTE_LENGTH_NO_CHECK (src); 7732 src += multibyte_length (src, NULL, false, true);
7731 } 7733 }
7732 } 7734 }
7733 7735