Skip to content

Commit c370615

Browse files
Zexiclaude
authored andcommitted
fix: cap diff size to prevent SQLite/V8 crash on large files
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7bac50f commit c370615

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

packages/opencode/src/tool/apply_patch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ export const ApplyPatchTool = Tool.define(
169169
),
170170
)
171171
const contentToDelete = source.text
172-
const deleteDiff = trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))
172+
// Skip diff for large/binary files to prevent storing hundreds of MB in SQLite.
173+
// V8 string limit is ~512MB; a 142MB binary file produces a 380MB+ diff.
174+
const DIFF_SIZE_LIMIT = 512 * 1024 // 512 KB
175+
const deleteDiff =
176+
contentToDelete.length > DIFF_SIZE_LIMIT
177+
? ""
178+
: trimDiff(createTwoFilesPatch(filePath, filePath, contentToDelete, ""))
173179

174180
const deletions = contentToDelete.split("\n").length
175181

packages/opencode/src/tool/edit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,10 @@ export const ContextAwareReplacer: Replacer = function* (content, find) {
635635
}
636636
}
637637

638+
const DIFF_MAX_BYTES = 512 * 1024 // 512 KB — keeps SQLite rows manageable and well under V8's string limit
639+
638640
export function trimDiff(diff: string): string {
641+
if (diff.length > DIFF_MAX_BYTES) return ""
639642
const lines = diff.split("\n")
640643
const contentLines = lines.filter(
641644
(line) =>

0 commit comments

Comments
 (0)