diff --git a/builtin-apply.c b/builtin-apply.c
index 25b1447901d4085bdc5b554451c5e79b72cbae12..976ec770417cba4113c4c55f5ca7a5f7b8520f1e 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1514,7 +1514,8 @@ static int find_offset(const char *buf, unsigned long size, const char *fragment
}
/* Exact line number? */
- if (!memcmp(buf + start, fragment, fragsize))
+ if ((start + fragsize <= size) &&
+ !memcmp(buf + start, fragment, fragsize))
return start;
/*