Repository navigation
fix(acp): reject fractional readTextFile limits #6704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1879,6 +1879,16 @@ export class BridgeClient implements Client { | |||||||||||||||||||||
| if (typeof params.limit === 'number' && params.limit <= 0) { | ||||||||||||||||||||||
| return { content: '' }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if ( | ||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The guard condition
Suggested change
— qwen3.7-max via Qwen Code /review |
||||||||||||||||||||||
| typeof params.limit === 'number' && | ||||||||||||||||||||||
| params.limit > 0 && | ||||||||||||||||||||||
| !Number.isSafeInteger(params.limit) | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The new inline guard correctly throws Consider having — qwen3.7-max via Qwen Code /review
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, addressed. I updated preserveFsErrorOverAcp() so FsError('parse_error') maps to JSON-RPC Invalid Params (-32602) while preserving the existing data.errorKind, data.status, and data.hint fields. Other filesystem error kinds still use the existing internal-error mapping. |
||||||||||||||||||||||
| throw RequestError.invalidParams( | ||||||||||||||||||||||
| undefined, | ||||||||||||||||||||||
| '`limit` must be a positive integer.', | ||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, done. The inline fallback now includes the received value in both invalid-params messages: line and limit report the malformed value that was rejected. |
||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| // BSA0E: cap the file size we'll buffer into RSS at 100 MiB so a | ||||||||||||||||||||||
| // request like `{ line: 1, limit: 10 }` against a 500 MB log | ||||||||||||||||||||||
| // doesn't cost the daemon 500 MB of memory just to return 10 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,6 +365,28 @@ describe('createBridgeFileSystemAdapter', () => { | |
| }); | ||
| expect(response.content).toBe('x\ny\n'); | ||
| }); | ||
|
|
||
| it('propagates parse_error for fractional positive limits', async () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, renamed. The adapter test now explicitly says it surfaces the existing WorkspaceFileSystem.readText() parse_error behavior, so it should no longer look like coverage for the new inline fallback guard. |
||
| const target = path.join(tmpDir, 'fractional-limit.txt'); | ||
| await fsp.writeFile(target, 'x\ny\nz\n', 'utf8'); | ||
| const adapter = createBridgeFileSystemAdapter( | ||
| buildFactory({ trusted: true }), | ||
| ); | ||
|
|
||
| const err = await adapter | ||
| .readText({ | ||
| path: target, | ||
| sessionId: 'sess:test', | ||
| line: 1, | ||
| limit: 1.5, | ||
| }) | ||
| .catch((e: unknown) => e); | ||
|
|
||
| expect((err as { kind?: string }).kind).toBe('parse_error'); | ||
| expect((err as Error).message).toContain( | ||
| 'limit must be a positive integer', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('boundary enforcement', () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, addressed in the latest push. I added the symmetric positive-integer guard for line in the inline fallback, so fractional line values now fail before reaching sliceLineRange(), matching the limit validation shape.