Skip to content

fix(mcp): an integer argument outside int range takes the default - #2256

Open
DeusData wants to merge 1 commit into
mainfrom
distill/1245-int-arg-range
Open

DeusData wants to merge 1 commit into
mainfrom
distill/1245-int-arg-range

Conversation

@DeusData

Copy link
Copy Markdown
Owner

Distilled from #1245 by @ahundt (d030c8f), carried with Co-authored-by. #1245 stays open until its distills land.

The bug

cbm_mcp_get_int_arg read integers with yyjson_get_int, whose int cast truncates. {"limit": 4294967297} — 2³² + 1 — returned 1: the low word of the value, silently, as a bound. The same reader serves limit and offset on the query tools, so an oversized page request became a page of one.

The fix

Read as a 64-bit signed or unsigned integer; accept only if it fits in int; anything outside takes the caller's default, exactly as a non-integer does. In-range values and non-integer JSON are unchanged. ~12 lines.

RED → GREEN

mcp_get_int_arg  FAIL tests/test_mcp.c:1777: val == 1, expected 17 == 17

The test now covers 2³²+1, its negative, INT_MAX+1 and INT64_MIN each returning a distinct default, and INT_MAX / INT_MIN / −7 passing through unchanged.

After: mcp 318 passed, 4 skipped; mcp cli daemon_application 692 passed, 0 failed.

Distilled from #1245 by Andrew Hundt (d030c8f).

cbm_mcp_get_int_arg read integer arguments with yyjson_is_int and
yyjson_get_int, and the int cast inside get_int truncates. A client
sending {"limit": 4294967297} -- 2^32 + 1 -- got back 1: the low word of
the value, silently, as a bound. The same read serves limit and offset
on the query tools, so an oversized page request became a page of one.

The argument is now read as a 64-bit signed or unsigned integer and only
accepted if it fits in int; anything outside the range takes the
caller's default, exactly as a non-integer does. In-range values and
non-integer JSON behave as before. One difference from the upstream
hunk: the unsigned comparison casts INT_MAX explicitly rather than
relying on the implicit conversion.

RED before the fix:
  mcp_get_int_arg  FAIL tests/test_mcp.c:1777: val == 1, expected 17 == 17

The test now covers 2^32 + 1, its negative, INT_MAX + 1 and INT64_MIN
each returning a distinct default, and INT_MAX, INT_MIN and -7 passing
through unchanged.

GREEN after: mcp 318 passed, 4 skipped (the Windows-only skips);
mcp cli daemon_application 692 passed, 0 failed.

Co-authored-by: Andrew Hundt <ATHundt@gmail.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant