Commit Diff


commit - ada5f162499576f0ff8a10320baf70872ec476464db0188eac110e14b05cca6a
commit + 274e82cea6946259b0d3bc09513fee0d52e39377dfe026fe701b218a3ae7e048
blob - a2d0390b690ca4022722dc267846b00aebb6b737c845c6bc6573903a513863de
blob + 444fc618d9c701f076fdb776ddaf8bcfa69bc5e3fad8b660b6ed49c6410a689d
--- lib/object.c	
+++ lib/object.c	
@@ -21,6 +21,7 @@
 #include <sys/uio.h>
 #include <sys/mman.h>
 
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -374,7 +375,7 @@ const struct got_error *
 got_object_blob_is_binary(int *binary, struct got_blob_object *blob)
 {
 	const struct got_error *err;
-	size_t hdrlen, len;
+	size_t hdrlen, len, i;
 
 	*binary = 0;
 	hdrlen = got_object_blob_get_hdrlen(blob);
@@ -386,7 +387,13 @@ got_object_blob_is_binary(int *binary, struct got_blob
 	if (err)
 		return err;
 
-	*binary = memchr(blob->read_buf, '\0', len) != NULL;
+	for (i = 0; i < len; ++i) {
+		if (iscntrl((unsigned char)blob->read_buf[i]) &&
+		    !isspace((unsigned char)blob->read_buf[i])) {
+			*binary = 1;
+			break;
+		}
+	}
 
 	if (fseeko(blob->f, hdrlen, SEEK_SET) == -1)
 		return got_error_from_errno("fseeko");