Skip to content

Fix/transport length parse ub - #6

Merged
abcsnowwolf merged 5 commits into
mainfrom
fix/transport-length-parse-ub
Jul 24, 2026
Merged

Fix/transport length parse ub#6
abcsnowwolf merged 5 commits into
mainfrom
fix/transport-length-parse-ub

Conversation

@abcsnowwolf

Copy link
Copy Markdown
Contributor

No description provided.

* assemble the START frame's 4-byte length as uint32_t: uint8_t promotes to int, so a first byte >= 0x80 shifted left by 24 overflowed the signed range (UB) before the size check ran
* wire format and observable behavior unchanged: oversized declared lengths are still rejected with MESSAGE_TOO_LARGE, so clients need no update
* add regression test declaring a 0xFFFFFFFF total so the native-san (UBSan) job now guards this path
* add ToolHandler::call(params, bool& isError) overload with a default that delegates to the legacy call(params) and reports success, so existing handlers compile and behave unchanged
* dispatcher now honors the flag: failures produce a tools/call RESULT with isError=true (not a JSON-RPC error) so LLM clients can see and react to the failure, per MCP spec
* omit structuredContent on error since an error payload would not conform to a declared outputSchema
* add FailingHandler test covering the error path; legacy path stays covered by test_handle_tool_call_success
* document the error-reporting contract in the README API reference
* unknown tool now returns -32602 (invalid params) with "Unknown tool: <name>" instead of -32601, matching the spec: the tools/call method itself exists
* attach structuredContent only when the handler result is a JSON object, as the spec defines it as an object; scalar/array/null results still reach the client as serialized text content
* update the unknown-tool test and add a scalar-result regression test
* new backwards-compatible ToolHandler error-reporting API (result.isError)
* MCP spec alignment: unknown tool returns -32602, structuredContent only for object results
* fix signed-shift UB in fragment length parsing (no wire/behavior change)
* caret on 0.x does not cross minors, so ^0.1.0 would never resolve to 0.2.0
@abcsnowwolf
abcsnowwolf merged commit ed93777 into main Jul 24, 2026
10 checks passed
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