-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Fix EISDIR warnings and Max Stack Size errors for issue #21527 #25444
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 all commits
657e630
d3481c9
ea51c67
96a80eb
382e95b
f22a6de
a66b75e
d798185
8ca46e3
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,13 +8,14 @@ import fs from 'node:fs'; | |||||
| import fsPromises from 'node:fs/promises'; | ||||||
| import path from 'node:path'; | ||||||
| import type { PartUnion } from '@google/genai'; | ||||||
| import { isBinaryFile as isBinaryFileCheck } from 'isbinaryfile'; | ||||||
| import mime from 'mime/lite'; | ||||||
|
Contributor
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. The
Suggested change
|
||||||
| import type { FileSystemService } from '../services/fileSystemService.js'; | ||||||
| import { ToolErrorType } from '../tools/tool-error.js'; | ||||||
| import { BINARY_EXTENSIONS } from './ignorePatterns.js'; | ||||||
| import { createRequire as createModuleRequire } from 'node:module'; | ||||||
| import { debugLogger } from './debugLogger.js'; | ||||||
| import { resolveToRealPath } from './paths.js'; | ||||||
| import { isBinaryFile as isBinaryFileCheck } from 'isbinaryfile'; | ||||||
| import { | ||||||
| DEFAULT_MAX_LINES_TEXT_FILE, | ||||||
| MAX_LINE_LENGTH_TEXT_FILE, | ||||||
|
|
@@ -346,11 +347,13 @@ export async function isEmpty(filePath: string): Promise<boolean> { | |||||
|
|
||||||
| /** | ||||||
| * Heuristic: determine if a file is likely binary. | ||||||
| * Delegates to the `isbinaryfile` package for UTF-8-aware detection. | ||||||
| */ | ||||||
| export async function isBinaryFile(filePath: string): Promise<boolean> { | ||||||
| try { | ||||||
| return await isBinaryFileCheck(filePath); | ||||||
| const realPath = resolveToRealPath(filePath); | ||||||
| const stats = await fsPromises.stat(realPath); | ||||||
| if (stats.isDirectory()) return false; | ||||||
|
Contributor
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. A Denial of Service (DoS) vulnerability exists in the isBinaryFile function. If the resolved path points to a special file (e.g., named pipe, device file) and is not verified as a regular file before being passed to isBinaryFileCheck, the subsequent read operation could block indefinitely. Additionally, ensure you use asynchronous file system operations (e.g., fs.promises.realpath) instead of synchronous ones to avoid blocking the event loop. This utility should validate its path inputs internally and continue to use resolveToRealPath for consistent path resolution.
Suggested change
References
|
||||||
| return await isBinaryFileCheck(realPath); | ||||||
| } catch (error) { | ||||||
| debugLogger.warn( | ||||||
| `Failed to check if file is binary: ${filePath}`, | ||||||
|
|
||||||
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.
The
depthparameter and the checkif (depth > 2)have been added to prevent aRangeError: Maximum call stack size exceeded, but the implementation appears incomplete. There is no recursive call tohandleAtCommandwithin this function, nor is thedepthparameter incremented and passed to any other function that might call it back. Consequently,depthwill always remain at its default value of0, and the check will never trigger. If the recursion is intended to happen within this function (e.g., to expand nested@commands in the content of read files), the recursive call is missing. If the recursion happens in the caller, the caller must be updated to pass an incrementeddepthvalue.References