Commit Diff


commit - c1b420179b3673008ca7ac2af3156849b9d2059f
commit + 98958d75e928ddd95151c462562d1b91b172f7e9
blob - b58b9970c4f4924c6663e2de3b426bcf71082141
blob + 06abb6ddaffb5523a3e826747ee2617cc41972b3
--- 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");