@matheusbsbs / matheus-bagliano / commits / 9add69b1b1
Fork 0

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>

Junio C Hamano committed Nov 14, 2005 at 17:15 UTC 9add69b1b1f76db874ed899c46fbe0b252aa3c23
1 file changed +4 -3
apply.c
+4 -3
@@ -370,7 +370,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
370 int len;
371
372 ptr = strchr(line, '.');
373 - if (!ptr || ptr[1] != '.' || 40 <= ptr - line)
373 + if (!ptr || ptr[1] != '.' || 40 < ptr - line)
374 return 0;
375 len = ptr - line;
376 memcpy(patch->old_sha1_prefix, line, len);
@@ -384,7 +384,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
384 ptr = eol;
385 len = ptr - line;
386
387 - if (40 <= len)
387 + if (40 < len)
388 return 0;
389 memcpy(patch->new_sha1_prefix, line, len);
390 patch->new_sha1_prefix[len] = 0;
@@ -895,7 +895,8 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
895 static const char binhdr[] = "Binary files ";
896
897 if (sizeof(binhdr) - 1 < size - offset - hdrsize &&
898 - !memcmp(binhdr, buffer + hdrsize, sizeof(binhdr)-1))
898 + !memcmp(binhdr, buffer + hdrsize + offset,
899 + sizeof(binhdr)-1))
900 patch->is_binary = 1;
901
902 if (patch->is_binary && !apply && !check)