mirror of
https://github.com/neovim/neovim.git
synced 2026-03-30 12:22:08 +00:00
fix(mpack): boundary values for negative integer encoding #37255
Problem: libmpack encodes boundary values -129 and -32769 with wrong integer sizes: - -129 as int8 instead of int16 - -32769 as int16 instead of int32 because the boundary checks compare against the wrong values (e.g., lo < 0xffffff7f instead of lo < 0xffffff80). This caused data corruption: -129 would decode as 127. Solution: Fix off-by-one errors in the two's complement boundary constants: 0xffffff80 (-128, min int8) and 0xffff8000 (-32768, min int16). Fixes #37202 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
local t = require('test.unit.testutil')
|
||||
local cimport = t.cimport
|
||||
local itp = t.gen_itp(it)
|
||||
local lib = cimport('./src/nvim/msgpack_rpc/unpacker.h', './src/nvim/memory.h')
|
||||
local lib =
|
||||
cimport('./src/nvim/msgpack_rpc/unpacker.h', './src/nvim/memory.h', './src/mpack/conv.h')
|
||||
local ffi = t.ffi
|
||||
local eq = t.eq
|
||||
local to_cstr = t.to_cstr
|
||||
@@ -77,3 +78,31 @@ describe('msgpack', function()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('libmpack', function()
|
||||
describe('mpack_pack_number', function()
|
||||
itp('token length at negative integer boundaries #37202', function()
|
||||
-- tok.length is the byte count for the integer value (not including the msgpack type prefix byte).
|
||||
|
||||
-- int8 min: -128 → 1 byte
|
||||
local tok = lib.mpack_pack_number(-128)
|
||||
eq(lib.MPACK_TOKEN_SINT, tok.type)
|
||||
eq(1, tok.length)
|
||||
|
||||
-- one past int8: -129 → 2 bytes (int16)
|
||||
tok = lib.mpack_pack_number(-129)
|
||||
eq(lib.MPACK_TOKEN_SINT, tok.type)
|
||||
eq(2, tok.length)
|
||||
|
||||
-- int16 min: -32768 → 2 bytes
|
||||
tok = lib.mpack_pack_number(-32768)
|
||||
eq(lib.MPACK_TOKEN_SINT, tok.type)
|
||||
eq(2, tok.length)
|
||||
|
||||
-- one past int16: -32769 → 4 bytes (int32)
|
||||
tok = lib.mpack_pack_number(-32769)
|
||||
eq(lib.MPACK_TOKEN_SINT, tok.type)
|
||||
eq(4, tok.length)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user