Skip to content

Commit 34e6d45

Browse files
committed
fix: panic in linear myers algorithm
In `linearSpaceMyersRecWithIndices`, the suffix-scanning loop: ```go for suffix < n-prefix && a[aEnd-1-suffix] == b[bEnd-1-suffix] { ``` bounds the scan against n-prefix (a's remaining length after prefix) but not against m-prefix (b's remaining length). With the fuzzer's input a="\n\n\n\n\n\n\n\n\n0" → 10 lines, b="0" → 1 line: n=10, m=1, prefix=0 suffix=0: a[9]="0" == b[0]="0" → true, suffix becomes 1 suffix=1: tries b[1-1-1] = b[-1] → index out of range panic Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent a1f8b87 commit 34e6d45

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

diff/myers/myers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func linearSpaceMyersRecWithIndices(a, b []string, aStart, aEnd, bStart, bEnd, d
217217
}
218218

219219
suffix := 0
220-
for suffix < n-prefix && a[aEnd-1-suffix] == b[bEnd-1-suffix] {
220+
for suffix < n-prefix && suffix < m-prefix && a[aEnd-1-suffix] == b[bEnd-1-suffix] {
221221
suffix++
222222
}
223223

0 commit comments

Comments
 (0)