commit e650a842f69a783ed41a073df81eac7e8490b003 from: Omar Polo via: Thomas Adam date: Wed Aug 06 12:48: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 - c1e3a5dcf911a2de8acb7b561ae0431563f5c456 commit + e650a842f69a783ed41a073df81eac7e8490b003 blob - eab399777a9e609d5c47a051ccb6670648eb8fb3 blob + 3587c86ce3d30a31f0f14059600eb50a93afc294 --- lib/object.c +++ lib/object.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -373,7 +374,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); @@ -385,7 +386,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");