fix(messages): disallow user-defined integer message-id #38359

Problem:
`nvim_echo(…, {id=…})` accepts user-defined id as a string or integer.
Generated ids are always higher than last highest msg-id used. Thus
plugins may accidentally advance the integer id "address space", which,
at minimum, could lead to confusion when troubleshooting, or in the
worst case, could overflow or "exhaust" the id address space.

There's no use-case for it, and it could be the mildly confusing, so we
should just disallow it.

Solution:
Disallow *integer* user-defined message-id.
Only allow *string* user-defined message-id.
This commit is contained in:
Justin M. Keyes
2026-03-18 21:07:17 -04:00
committed by GitHub
parent 4430c9a424
commit 1b2b715389
6 changed files with 33 additions and 15 deletions

View File

@@ -3821,6 +3821,11 @@ describe('API', function()
pcall_err(api.nvim_echo, { { '', '', '' } }, 1, {})
)
eq("Invalid 'hl_group': 'text highlight'", pcall_err(api.nvim_echo, { { '', false } }, 1, {}))
eq("Invalid 'id': 4", pcall_err(api.nvim_echo, { { 'foo' } }, false, { id = 4 }))
eq("Invalid 'id': 0", pcall_err(api.nvim_echo, { { 'foo' } }, false, { id = 0 }))
eq("Invalid 'id': -1", pcall_err(api.nvim_echo, { { 'foo' } }, false, { id = -1 }))
-- String ids are always allowed (user-defined).
eq('my.msg.id', api.nvim_echo({ { 'foo' } }, false, { id = 'my.msg.id' }))
end)
it('should clear cmdline message before echo', function()
@@ -3913,8 +3918,8 @@ describe('API', function()
it('increments message ID', function()
eq(1, api.nvim_echo({ { 'foo' } }, false, {}))
eq(4, api.nvim_echo({ { 'foo' } }, false, { id = 4 }))
eq(5, api.nvim_echo({ { 'foo' } }, false, {}))
eq(1, api.nvim_echo({ { 'foo' } }, false, { id = 1 })) -- User may pass existing id.
eq(2, api.nvim_echo({ { 'foo' } }, false, {}))
end)
it('no use-after-free for custom kind with :messages #38289', function()