fix: handle RangeError in isbinaryfile library

- Add try-catch blocks around all isBinaryFile calls
- Treat files as binary when isbinaryfile throws RangeError
- Prevents extension from freezing when processing certain files
- Fixes #6242
This commit is contained in:
Roo Code 2025-07-26 10:17:13 +00:00
parent 62160758fc
commit 17b08730dc
3 changed files with 27 additions and 3 deletions

View file

@ -268,7 +268,14 @@ async function getFileOrFolderContent(
fileContentPromises.push(
(async () => {
try {
const isBinary = await isBinaryFile(absoluteFilePath).catch(() => false)
let isBinary = false
try {
isBinary = await isBinaryFile(absoluteFilePath)
} catch (error) {
// If isBinaryFile throws an error (e.g., RangeError), treat as binary
console.warn(`Error checking if file is binary for ${absoluteFilePath}:`, error)
isBinary = true
}
if (isBinary) {
return undefined
}

View file

@ -433,7 +433,17 @@ export async function readFileTool(
// Process approved files
try {
const [totalLines, isBinary] = await Promise.all([countFileLines(fullPath), isBinaryFile(fullPath)])
let totalLines: number
let isBinary: boolean
try {
;[totalLines, isBinary] = await Promise.all([countFileLines(fullPath), isBinaryFile(fullPath)])
} catch (error) {
// If isBinaryFile throws an error (e.g., RangeError), treat the file as binary
console.warn(`Error checking if file is binary for ${relPath}:`, error)
totalLines = await countFileLines(fullPath)
isBinary = true
}
// Handle binary files (but allow specific file types that extractTextFromFile can handle)
if (isBinary) {

View file

@ -86,7 +86,14 @@ export async function extractTextFromFile(filePath: string, maxReadFileLine?: nu
}
// Handle other files
const isBinary = await isBinaryFile(filePath).catch(() => false)
let isBinary = false
try {
isBinary = await isBinaryFile(filePath)
} catch (error) {
// If isBinaryFile throws an error (e.g., RangeError), treat as binary
console.warn(`Error checking if file is binary for ${filePath}:`, error)
isBinary = true
}
if (!isBinary) {
// Check if we need to apply line limit