aboutsummaryrefslogtreecommitdiffstats
path: root/ui-tree.c
diff options
context:
space:
mode:
authorJune McEnroe2019-12-18 21:30:12 +0000
committerYigit Sever2023-07-21 03:03:49 +0300
commit1c9e818ddb4ad4601f3180cd9163625bd087f03a (patch)
tree8c27ec40c2f0a5e00c412dfed05360a340e12992 /ui-tree.c
parentcafd9178eb039f859fbdc85c5c006331e3222f33 (diff)
downloadcgit-1c9e818ddb4ad4601f3180cd9163625bd087f03a.tar.gz
cgit-1c9e818ddb4ad4601f3180cd9163625bd087f03a.tar.bz2
cgit-1c9e818ddb4ad4601f3180cd9163625bd087f03a.zip
ui-tree,ui-blame: bail from blame if blob is binary
This avoids piping binary blobs through the source-filter. Also prevent robots from crawling it, since it's expensive. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui-tree.c')
-rw-r--r--ui-tree.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ui-tree.c b/ui-tree.c
index fbaaa32..4657c37 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -89,6 +89,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
89 enum object_type type; 89 enum object_type type;
90 char *buf; 90 char *buf;
91 unsigned long size; 91 unsigned long size;
92 bool is_binary;
92 93
93 type = oid_object_info(the_repository, oid, &size); 94 type = oid_object_info(the_repository, oid, &size);
94 if (type == OBJ_BAD) { 95 if (type == OBJ_BAD) {
@@ -103,6 +104,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
103 "Error reading object %s", oid_to_hex(oid)); 104 "Error reading object %s", oid_to_hex(oid));
104 return; 105 return;
105 } 106 }
107 is_binary = buffer_is_binary(buf, size);
106 108
107 cgit_set_title_from_path(path); 109 cgit_set_title_from_path(path);
108 110
@@ -110,7 +112,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
110 htmlf("blob: %s (", oid_to_hex(oid)); 112 htmlf("blob: %s (", oid_to_hex(oid));
111 cgit_plain_link("plain", NULL, NULL, ctx.qry.head, 113 cgit_plain_link("plain", NULL, NULL, ctx.qry.head,
112 rev, path); 114 rev, path);
113 if (ctx.repo->enable_blame) { 115 if (ctx.repo->enable_blame && !is_binary) {
114 html(") ("); 116 html(") (");
115 cgit_blame_link("blame", NULL, NULL, ctx.qry.head, 117 cgit_blame_link("blame", NULL, NULL, ctx.qry.head,
116 rev, path); 118 rev, path);
@@ -123,7 +125,7 @@ static void print_object(const struct object_id *oid, const char *path, const ch
123 return; 125 return;
124 } 126 }
125 127
126 if (buffer_is_binary(buf, size)) 128 if (is_binary)
127 print_binary_buffer(buf, size); 129 print_binary_buffer(buf, size);
128 else 130 else
129 print_text_buffer(basename, buf, size); 131 print_text_buffer(basename, buf, size);