commit 98958d75e928ddd95151c462562d1b91b172f7e9 from: Omar Polo date: Thu Jul 31 17:09:03 2025 UTC improve binary blob detection just like the change just done in diff.git, consider a blob binary if it has any control character (except for the tabs) joint work with jtt@, ok stsp@ commit - c1b420179b3673008ca7ac2af3156849b9d2059f commit + 98958d75e928ddd95151c462562d1b91b172f7e9 blob - b58b9970c4f4924c6663e2de3b426bcf71082141 blob + 06abb6ddaffb5523a3e826747ee2617cc41972b3 --- lib/object.c +++ lib/object.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -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");