Repository navigation
Description
Problem
The Cursor protobuf map decoder can read past an entry's declared payload length. In compileMapField, the loop checks the entry's end before each field, but the key/value decoding and unknown-field skips use the enclosing message's Reader. Those operations can consume bytes outside the entry.
This is reproducible through the production McpArgsSchema.decode → decodeCursorTool path: changing a valid map entry's length from 10 to 9, while keeping its bytes unchanged, still produces a decoded Pi tool call with arguments: { url: "x" }.
Reproduction
Source: a18f457687b45c877bc8a15d689a7580c4f0659a (current main when checked on 2026-10-11). Environment: Windows, Node v24.12.0, Bun 1.3.14, checkout dependencies with Pi SDK 0.99.1.
With the checkout dependencies installed, save the following as repro-map-entry.mjs in the repository root and run:
node --experimental-strip-types repro-map-entry.mjsimport { Type } from "typebox";
import { McpArgsSchema } from "./extensions/ai-providers/cursor/proto.ts";
import { decodeCursorTool } from "./extensions/ai-providers/cursor/tool-bridge.ts";
const tool = {
name: "lookup",
description: "Look up a page",
parameters: Type.Object({ url: Type.String() }),
};
const identity = McpArgsSchema.encode(McpArgsSchema.create({
name: "lookup",
toolName: "lookup",
providerIdentifier: "openpi",
toolCallId: "lookup-1",
}));
const valid = Buffer.from("120a0a0375726c12031a0178", "hex");
const malformed = Buffer.from(valid);
malformed[1] = 9; // Declared length 9; the payload still contains 10 bytes.
for (const [label, entry] of [["valid", valid], ["malformed", malformed]]) {
try {
const decoded = McpArgsSchema.decode(Buffer.concat([identity, entry]));
console.log(label, JSON.stringify(decodeCursorTool(decoded, [tool])));
} catch (error) {
console.log(label, String(error));
}
}Actual output on the unmodified decoder:
valid {"type":"toolCall","id":"lookup-1","name":"lookup","arguments":{"url":"x"}}
malformed {"type":"toolCall","id":"lookup-1","name":"lookup","arguments":{"url":"x"}}
The script only decodes the call; it does not execute a tool or contact a provider.
Expected behavior
The valid entry should decode as before. The malformed entry should throw before tool handoff, rather than borrow bytes from outside its declared payload. Protobuf maps are repeated length-delimited entry messages; see the official wire-format guide.
Proposed fix and local validation
I have a minimal fix and regression tests prepared locally: create new Reader(reader.bytes()) per map entry, and use it for all key/value reads and unknown-field skips. This follows the codec's existing bounded-reader pattern for nested messages.
- Confirmed regression run on the original decoder: 6 passes / 6 missing-exception failures. With the fix: 12/12 pass.
- Coverage includes key/value overruns, unknown varint/LEN/fixed32/fixed64 overruns, truncated entry payloads, and valid defaults, duplicate keys, multiple entries, sibling fields, and unknown fields.
- Related Cursor suites: 55/55 pass.
bun run check: passed. bun run testis not fully green: the Node parallel group has 2,213 passes, 5 failures, and 14 skips. The same five failures reproduce in the unchanged baseline Web suites; four directly report Windows symlinkEPERM, and one is achanged-sessionassertion failure. Separately completed serial tests: 99 passes / 4 skips; UI tests: 82 files / 1,158 passes.
The evidence is limited to offline source-level decoding. I have not observed a real Cursor server send these malformed bytes, reproduced a live user incident, or validated installed-runtime/TUI behavior.
Related work
The 2026-10-11 duplicate check covered Issue/PR searches, PR metadata across all states, and all 58 open PR file lists; no matching fix was found within that scope. The searches were refreshed immediately before this report.
#269 introduced the codec; #432 addresses frame buffering/context boundaries; #693 changes advertised tool naming. They do not address this map-entry boundary. No fix PR has been opened for this report yet.
Activity
outlier27-cell commentedon Oct 11, 2026
I am claiming this report because no implementation PR or active claim is present. I will preserve valid map decoding, reject every declared-entry overrun before Cursor tool handoff, add focused codec regressions, and submit an isolated PR.