aboutsummaryrefslogtreecommitdiff
path: root/apply.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-11-14 17:15:07 -0800
committerJunio C Hamano <junkio@cox.net>2005-11-14 17:15:07 -0800
commit9add69b1b1f76db874ed899c46fbe0b252aa3c23 (patch)
treef2f66041e72c49a6badf3451e642ffdd507c35c2 /apply.c
parent2ed02887bda74871bad64f1be36fb4f60d07706e (diff)
downloadgit-9add69b1b1f76db874ed899c46fbe0b252aa3c23.tar.gz
git-9add69b1b1f76db874ed899c46fbe0b252aa3c23.tar.xz
apply: fix binary patch detection.
The comparison to find "Binary files " string was looking at a wrong place when offset != 0. Also, we may have the full 40-byte textual sha1 on the index line; two off-by-one errors prevented it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/apply.c b/apply.c
index 34181188b..590adc6af 100644
--- a/apply.c
+++ b/apply.c
@@ -370,7 +370,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
int len;
ptr = strchr(line, '.');
- if (!ptr || ptr[1] != '.' || 40 <= ptr - line)
+ if (!ptr || ptr[1] != '.' || 40 < ptr - line)
return 0;
len = ptr - line;
memcpy(patch->old_sha1_prefix, line, len);
@@ -384,7 +384,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
ptr = eol;
len = ptr - line;
- if (40 <= len)
+ if (40 < len)
return 0;
memcpy(patch->new_sha1_prefix, line, len);
patch->new_sha1_prefix[len] = 0;
@@ -895,7 +895,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
static const char binhdr[] = "Binary files ";
if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
- !memcmp(binhdr, buffer + hdrsize, sizeof(binhdr)-1))
+ !memcmp(binhdr, buffer + hdrsize + offset,
+ sizeof(binhdr)-1))
patch->is_binary = 1;
if (patch->is_binary && !apply && !check)