Fix a potential crash when trying to find a better block match.
[rsync/rsync.git] / match.c
diff --git a/match.c b/match.c
index 9da18a7..f327fd3 100644 (file)
--- a/match.c
+++ b/match.c
@@ -239,8 +239,9 @@ static void hash_search(int f,struct sum_struct *s,
                                        aligned_offset += s->blength;
                                        aligned_i++;
                                }
-                               if (offset == aligned_offset
-                                || (sum == 0 && l == s->blength && aligned_offset + l <= len)) {
+                               if ((offset == aligned_offset
+                                 || (sum == 0 && l == s->blength && aligned_offset + l <= len))
+                                && aligned_i < s->count) {
                                        if (i != aligned_i) {
                                                if (sum != s->sums[aligned_i].sum1
                                                 || l != s->sums[aligned_i].len