Repository navigation
fix(core): resolve EISDIR errors during file processing (#21527) #27041
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 2 commits
35cbd3b
a78b047
7723cde
e0cb2b7
5b75511
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ 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 { | ||||||||||||||||||
| DEFAULT_MAX_LINES_TEXT_FILE, | ||||||||||||||||||
| MAX_LINE_LENGTH_TEXT_FILE, | ||||||||||||||||||
|
|
@@ -350,7 +351,10 @@ export async function isEmpty(filePath: string): Promise<boolean> { | |||||||||||||||||
| */ | ||||||||||||||||||
| 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; | ||||||||||||||||||
| return await isBinaryFileCheck(realPath); | ||||||||||||||||||
|
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. While resolveToRealPath is synchronous, its use is required for consistent path resolution and internal validation to prevent path traversal vulnerabilities (Rule 3, Rule 9). To improve performance and avoid redundant I/O, use fs.promises.stat asynchronously to check for directories and pass the resulting size to the binary check (Rule 4). Additionally, ensure all built-in Node.js modules use the node: prefix for imports (Rule 8).
Suggested change
References
|
||||||||||||||||||
| } 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.
Would this be better as !isFile() instead?
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.
You're right. isDirectory() will return false for sockets, FIFOs, and block devices, which would cause a potential hang. !isFile() would be the right choice for this matter , Thank you for the suggestion . As for resolveToRealPath, I'll remove, it was unnecessary overhead since we're only doing a check here, not exposing or writing the path anywhere.
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.
lemme fix those two parts