From def40180dcfb08bd5f5e3658b610995993a03a9a Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Fri, 21 Mar 2025 15:47:13 -0400 Subject: [PATCH] Don't do partial reads on binary files (#1886) --- src/core/Cline.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index b7bfc02118..20af9ee565 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -82,6 +82,7 @@ import { validateToolUse, isToolAllowedForMode, ToolName } from "./mode-validato import { parseXml } from "../utils/xml" import { readLines } from "../integrations/misc/read-lines" import { getWorkspacePath } from "../utils/path" +import { isBinaryFile } from "isbinaryfile" type ToolResponse = string | Array type UserContent = Array @@ -2324,6 +2325,8 @@ export class Cline extends EventEmitter { let isFileTruncated = false let sourceCodeDef = "" + const isBinary = await isBinaryFile(absolutePath).catch(() => false) + if (isRangeRead) { if (startLine === undefined) { content = addLineNumbers(await readLines(absolutePath, endLine, startLine)) @@ -2333,7 +2336,7 @@ export class Cline extends EventEmitter { startLine, ) } - } else if (totalLines > maxReadFileLine) { + } else if (!isBinary && totalLines > maxReadFileLine) { // If file is too large, only read the first maxReadFileLine lines isFileTruncated = true