From 1be85369f36458fe9a2f85ca63285367f94e6172 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 06:26:24 -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/shared.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source/shared.c') diff --git a/source/shared.c b/source/shared.c index 9065693..3191742 100644 --- a/source/shared.c +++ b/source/shared.c @@ -410,9 +410,7 @@ int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new *old_size = old_bytes; *new_size = new_bytes; - if (ctx.cfg.max_blob_size && - (old_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size || - new_bytes / 1024 > (unsigned long)ctx.cfg.max_blob_size)) { + if (cgit_blob_too_large(old_bytes) || cgit_blob_too_large(new_bytes)) { *binary = 1; return 0; } @@ -450,6 +448,11 @@ int cgit_diff_files(const struct object_id *old_oid, const struct object_id *new return 0; } +int cgit_blob_too_large(unsigned long size) +{ + return ctx.cfg.max_blob_size && size / 1024 > (unsigned long)ctx.cfg.max_blob_size; +} + void cgit_diff_limit_path(struct diff_options *opt, const char *prefix) { struct pathspec_item *item; -- cgit