Description
packages/opencode/src/tool/edit.ts line 742: the isDisproportionateMatch() function returns false immediately when oldString is a single line, bypassing all safety checks. This allows fuzzy replacers like LineTrimmedReplacer to match significantly larger blocks than intended.
Root Cause
function isDisproportionateMatch(search: string, oldString: string) {
const oldLines = oldString.split("\n").length
const searchLines = search.split("\n").length
if (searchLines >= Math.max(oldLines + 3, oldLines * 2)) return true
if (oldLines === 1) return false // <-- BUG: bypasses all checks
return search.trim().length > Math.max(oldString.trim().length + 500, oldString.trim().length * 4)
}
When oldString is a single line (e.g., "return value"), the function immediately returns false meaning "not disproportionate." A fuzzy replacer could match many lines where "return value" appears, modifying a much larger section than the user/AI intended.
Steps to reproduce
- Try to edit a single line like
"return result" in a large file
- If the exact match fails and falls to fuzzy replacers
- A much larger block containing
"return result" could be matched and replaced
OpenCode version
1.17.3
Description
packages/opencode/src/tool/edit.tsline 742: theisDisproportionateMatch()function returnsfalseimmediately whenoldStringis a single line, bypassing all safety checks. This allows fuzzy replacers likeLineTrimmedReplacerto match significantly larger blocks than intended.Root Cause
When
oldStringis a single line (e.g.,"return value"), the function immediately returnsfalsemeaning "not disproportionate." A fuzzy replacer could match many lines where"return value"appears, modifying a much larger section than the user/AI intended.Steps to reproduce
"return result"in a large file"return result"could be matched and replacedOpenCode version
1.17.3