diff --git a/src/getchar.c b/src/getchar.c index 3427a9f8da63fa65ef24b08e4eb5ff97627265b1..51842632ac9c7ec3e161cc630e10dca85b39401f 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -438,9 +438,18 @@ flush_buffers(flush_buffers_T flush_typeahead) if (flush_typeahead == FLUSH_MINIMAL) { - // remove mapped characters at the start only - typebuf.tb_off += typebuf.tb_maplen; - typebuf.tb_len -= typebuf.tb_maplen; + // remove mapped characters at the start only, + // but only when enough space left in typebuf + if (typebuf.tb_off + typebuf.tb_maplen >= typebuf.tb_buflen) + { + typebuf.tb_off = MAXMAPLEN; + typebuf.tb_len = 0; + } + else + { + typebuf.tb_off += typebuf.tb_maplen; + typebuf.tb_len -= typebuf.tb_maplen; + } #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) if (typebuf.tb_len == 0) typebuf_was_filled = FALSE; diff --git a/src/testdir/crash/heap_overflow3 b/src/testdir/crash/heap_overflow3 new file mode 100644 index 0000000000000000000000000000000000000000..c40adbec4d07a66bcc9aa51e40dbbb90fdc36623 Binary files /dev/null and b/src/testdir/crash/heap_overflow3 differ diff --git a/src/testdir/test_crash.vim b/src/testdir/test_crash.vim index fd786e5d545eefacedef4b5cef66198b3bb4d50f..0f494cf32142a35fdc7493b808493d3005411074 100644 --- a/src/testdir/test_crash.vim +++ b/src/testdir/test_crash.vim @@ -190,6 +190,12 @@ func Test_crash1_3() call term_sendkeys(buf, args) call TermWait(buf, 150) + let file = 'crash/heap_overflow3' + let cmn_args = "%s -u NONE -i NONE -n -X -m -n -e -s -S %s -c ':qa!'" + let args = printf(cmn_args, vim, file) + call term_sendkeys(buf, args) + call TermWait(buf, 150) + " clean up exe buf .. "bw!" bw!