Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Hold the mailmap to max-blob-size
git's read_mailmap_blob inflates the whole blob, so a pusher could make
every page of a repository read as much as they liked. git reads a
note and the .gitmodules file whole as well, and capping those would
mean bounding the lookups where the log, commit and tree pages make
them, so the manual names them instead. Nothing tested that
mailmap.file and mailmap.blob are ignored either.
| -rw-r--r-- | MANUAL.txt | 8 | |
| -rw-r--r-- | source/parsing.c | 12 | |
| -rwxr-xr-x | tests/t0303-robustness.sh | 31 |
3 files changed, 47 insertions, 4 deletions
@@ -402,9 +402,11 @@ max-blob-size:: memory to serve. The tree page's file view, the blame page, a tracked readme, a snapshot signature and the raw "plain" and "blob" output all refuse a larger object rather than load it whole, and the diff and patch - pages show it as binary. Whatever this is set to, the tree page shows no - more than the first 64 KB of a binary file as a hex dump, and links a - larger one to its "plain" output. Set to "0" to disable the limit. + pages show it as binary. A larger .mailmap is not applied, though a note + shown with a commit and a .gitmodules file are still read whole. Whatever + this is set to, the tree page shows no more than the first 64 KB of a + binary file as a hex dump, and links a larger one to its "plain" output. + Set to "0" to disable the limit. Default value: "10240" (10 MB). max-commit-count:: diff --git a/source/parsing.c b/source/parsing.c index f684241..909a288 100644 --- a/source/parsing.c +++ b/source/parsing.c @@ -24,11 +24,21 @@ static int mailmap_read; struct string_list *cgit_mailmap(void) { + struct object_id oid; + size_t size; + if (!ctx.repo || !ctx.repo->enable_mailmap) return NULL; if (!mailmap_read) { mailmap_read = 1; - read_mailmap_blob(the_repository, &mailmap, "HEAD:.mailmap"); + // git reads the blob whole, so it is held to the same bound as + // every other blob a page inflates. + if ( + !repo_get_oid(the_repository, "HEAD:.mailmap", &oid) && + odb_read_object_info(the_repository->objects, &oid, &size) == OBJ_BLOB && + !cgit_blob_too_large(size) + ) + read_mailmap_blob(the_repository, &mailmap, "HEAD:.mailmap"); } return mailmap.nr ? &mailmap : NULL; } diff --git a/tests/t0303-robustness.sh b/tests/t0303-robustness.sh index 2472bcd..b189334 100755 --- a/tests/t0303-robustness.sh +++ b/tests/t0303-robustness.sh @@ -935,4 +935,35 @@ test_expect_success 'descriptive values from a scanned repository are escaped' ' test_grep ! "<x>" tmp ' +# A repository's own config cannot point the mailmap reader at a file on the +# server or another blob, and git reads the mailmap whole, so one past +# max-blob-size is passed over like any other large blob. +test_expect_success 'only a .mailmap at HEAD within max-blob-size is applied' ' + test_create_repo repos/mapped && + ( + cd repos/mapped && + echo content >file && + git add file && + GIT_AUTHOR_NAME="Old Name" GIT_AUTHOR_EMAIL=old@example.com \ + git commit -q -m first && + echo "New Name <new@example.com> <old@example.com>" >.mailmap && + test_seq -f "# padding line %d" 1 200 >>.mailmap && + echo "Blob Name <blob@example.com> <old@example.com>" >other-map && + git add .mailmap other-map && + git commit -q -m "add the mailmaps" && + echo "File Name <file@example.com> <old@example.com>" >../map-on-disk && + git config mailmap.file "$PWD/../map-on-disk" && + git config mailmap.blob HEAD:other-map + ) && + test $(git -C repos/mapped cat-file -s HEAD:.mailmap) -ge 2048 && + cgitrc_repo mappedrc mapped && + cgit_ok mappedrc "url=mapped/log/" >tmp && + test_grep "<td class=.col-author.>New Name</td>" tmp && + test_grep ! -e "File Name" -e "Blob Name" tmp && + cgitrc_repo mappedcaprc mapped max-blob-size=1 && + cgit_ok mappedcaprc "url=mapped/log/" >tmp && + test_grep "<td class=.col-author.>Old Name</td>" tmp && + test_grep ! "New Name" tmp +' + test_done |
