Commits

Anonymous committed 9add69b

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>

Comments (0)

Files changed (1)

 	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);
 		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;
 		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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.