Skip to content

Commit def4018

Browse files
authored
Don't do partial reads on binary files (RooCodeInc#1886)
1 parent e075fbf commit def4018

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/core/Cline.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { validateToolUse, isToolAllowedForMode, ToolName } from "./mode-validato
8282
import { parseXml } from "../utils/xml"
8383
import { readLines } from "../integrations/misc/read-lines"
8484
import { getWorkspacePath } from "../utils/path"
85+
import { isBinaryFile } from "isbinaryfile"
8586

8687
type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
8788
type UserContent = Array<Anthropic.Messages.ContentBlockParam>
@@ -2324,6 +2325,8 @@ export class Cline extends EventEmitter<ClineEvents> {
23242325
let isFileTruncated = false
23252326
let sourceCodeDef = ""
23262327

2328+
const isBinary = await isBinaryFile(absolutePath).catch(() => false)
2329+
23272330
if (isRangeRead) {
23282331
if (startLine === undefined) {
23292332
content = addLineNumbers(await readLines(absolutePath, endLine, startLine))
@@ -2333,7 +2336,7 @@ export class Cline extends EventEmitter<ClineEvents> {
23332336
startLine,
23342337
)
23352338
}
2336-
} else if (totalLines > maxReadFileLine) {
2339+
} else if (!isBinary && totalLines > maxReadFileLine) {
23372340
// If file is too large, only read the first maxReadFileLine lines
23382341
isFileTruncated = true
23392342

0 commit comments

Comments
 (0)