diff options
author | June McEnroe | 2019-12-18 21:30:12 +0000 |
---|---|---|
committer | Yigit Sever | 2023-07-21 03:03:49 +0300 |
commit | 1c9e818ddb4ad4601f3180cd9163625bd087f03a (patch) | |
tree | 8c27ec40c2f0a5e00c412dfed05360a340e12992 | |
parent | cafd9178eb039f859fbdc85c5c006331e3222f33 (diff) | |
download | cgit-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>
-rw-r--r-- | robots.txt | 1 | ||||
-rw-r--r-- | ui-blame.c | 4 | ||||
-rw-r--r-- | ui-tree.c | 6 |
3 files changed, 9 insertions, 2 deletions
@@ -1,3 +1,4 @@ | |||
1 | User-agent: * | 1 | User-agent: * |
2 | Disallow: /*/snapshot/* | 2 | Disallow: /*/snapshot/* |
3 | Disallow: /*/blame/* | ||
3 | Allow: / | 4 | Allow: / |
@@ -152,6 +152,10 @@ static void print_object(const struct object_id *oid, const char *path, | |||
152 | cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); | 152 | cgit_tree_link("tree", NULL, NULL, ctx.qry.head, rev, path); |
153 | html(")\n"); | 153 | html(")\n"); |
154 | 154 | ||
155 | if (buffer_is_binary(buf, size)) { | ||
156 | html("<div class='error'>blob is binary.</div>"); | ||
157 | goto cleanup; | ||
158 | } | ||
155 | if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { | 159 | if (ctx.cfg.max_blob_size && size / 1024 > ctx.cfg.max_blob_size) { |
156 | htmlf("<div class='error'>blob size (%ldKB)" | 160 | htmlf("<div class='error'>blob size (%ldKB)" |
157 | " exceeds display size limit (%dKB).</div>", | 161 | " exceeds display size limit (%dKB).</div>", |
@@ -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); |