vim-patch:9.2.0436: Buffer overflow when parsing overlong errorformat lines (#39578)

Problem:  When an error line in a file passed to :cfile / :cgetfile is
          longer than IOSIZE, qf_parse_file_pfx() copies the tail
          into the fixed-size IObuff with STRMOVE(), overflowing the heap buffer.
          The same code path can also loop indefinitely because
          qf_parse_file_pfx() always returns QF_MULTISCAN when a
          tail is present, and qf_init_ext() unconditionally goes
          to "restofline" without bounding the tail length (Nabih).
Solution: Remove the STRMOVE() into IObuff.  In the QF_MULTISCAN
          branch, alias linebuf into the tail directly and update
          linelen, requiring strict progress (new length less than
          the previous length) before retrying; otherwise ignore
          the line.

closes: vim/vim#20126

Supported by AI

77677c33de

Co-authored-by: Christian Brabandt <cb@256bit.org>
(cherry picked from commit 0e69a38026)
This commit is contained in:
zeertzjq
2026-05-04 07:20:16 +08:00
committed by github-actions[bot]
parent 4f22640b86
commit f9f2596288
2 changed files with 30 additions and 2 deletions

View File

@@ -7028,4 +7028,26 @@ func Test_quickfix_longline_noeol()
call assert_equal(['okay'], readfile("XDONE"))
endfunc
func Test_efm_overlongline()
let save_efm = &efm
" %r captures the tail.
set efm=%+O(%.%#)%r,%f:%l:%m
" First line is longer than IOSIZE (1025) so the parser puts it in
" growbuf; the %r tail then far exceeds IObuff.
let lines = ['(short)' .. repeat('x', 4000), 'Xfile:10:msg']
call writefile(lines, 'Xqferrlong', 'D')
" Must complete without hanging or crashing.
cgetfile Xqferrlong
" The well-formed line that follows is still parsed.
let well_formed = filter(getqflist(), 'v:val.lnum == 10')
call assert_equal(1, len(well_formed))
call assert_equal('msg', well_formed[0].text)
let &efm = save_efm
call setqflist([], 'f')
endfunc
" vim: shiftwidth=2 sts=2 expandtab