From f7120603edc6f2680ad01fdbe7b3dc7ddf1494ef Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 27 Sep 2026 21:02:41 -1000 Subject: Share the max-blob-size check and its refusal Five copies of the test and four of the error page had to agree by hand. The new check pins the four refusals, which no test covered. --- source/ui-blob.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'source/ui-blob.c') diff --git a/source/ui-blob.c b/source/ui-blob.c index 3c3ba71..f7047c7 100644 --- a/source/ui-blob.c +++ b/source/ui-blob.c @@ -11,6 +11,7 @@ #include "cgit.h" #include "html.h" +#include "shared.h" #include "ui-blob.h" #include "ui-shared.h" @@ -94,15 +95,6 @@ static int find_path_oid(struct object_id *oid, char *path, int file_only) return walk.found_path; } -/* - * Callers ask before reading the object, so a huge blob stays out of - * memory rather than being noticed once already there. - */ -static int over_size_limit(unsigned long size) -{ - return ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size; -} - int cgit_ref_path_exists(const char *path, const char *ref, int file_only) { struct object_id oid; @@ -139,7 +131,7 @@ int cgit_print_file(char *path, const char *head, int file_only, int html_escape } if (type == OBJ_BAD) return -1; - if (over_size_limit(size)) + if (cgit_blob_too_large(size)) return -1; buf = odb_read_object(the_repository->objects, &oid, &type, &size); if (!buf) @@ -210,9 +202,8 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl return; } - if (over_size_limit(size)) { - cgit_print_error_page(413, "Content Too Large", "Blob size (%lu KB) exceeds the limit (%d KB)", - size / 1024, ctx.cfg.max_blob_size); + if (cgit_blob_too_large(size)) { + cgit_print_blob_too_large(size); return; } -- cgit 2.12.1