1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-10 20:26:14 +02:00
git/builtin
Jeff King 5f64279443 upload-pack: always turn off save_commit_buffer
When the client sends us "want $oid" lines, we call parse_object($oid)
to get an object struct. It's important to parse the commits because we
need to traverse them in the negotiation phase. But of course we don't
need to hold on to the commit messages for each one.

We've turned off the save_commit_buffer flag in get_common_commits() for
a long time, since f0243f26f6 (git-upload-pack: More efficient usage of
the has_sha1 array, 2005-10-28). That helps with the commits we see
while actually traversing. But:

  1. That function is only used by the v0 protocol. I think the v2
     protocol's code path leaves the flag on (and thus pays the extra
     memory penalty), though I didn't measure it specifically.

  2. If the client sends us a bunch of "want" lines, that happens before
     the negotiation phase. So we'll hold on to all of those commit
     messages. Generally the number of "want" lines scales with the
     refs, not with the number of objects in the repo. But a malicious
     client could send a lot in order to waste memory.

As an example of (2), if I generate a request to fetch all commits in
git.git like this:

  pktline() {
    local msg="$*"
    printf "%04x%s\n" $((1+4+${#msg})) "$msg"
  }

  want_commits() {
    pktline command=fetch
    printf 0001
    git cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype)' |
      while read oid type; do
        test "$type" = "commit" || continue
        pktline want $oid
      done
      pktline done
      printf 0000
  }

  want_commits | GIT_PROTOCOL=version=2 valgrind --tool=massif git-upload-pack . >/dev/null

before this patch upload-pack peaks at ~125MB, and after at ~35MB. The
difference is not coincidentally about the same as the sum of all commit
object sizes as computed by:

  git cat-file --batch-all-objects --batch-check='%(objecttype) %(objectsize)' |
  perl -alne '$v += $F[1] if $F[0] eq "commit"; END { print $v }'

In a larger repository like linux.git, that number is ~1GB.

In a repository with a full commit-graph file this will have no impact
(and the commit graph would save us from parsing at all, so is a much
better solution!). But it's easy to do, might help a little in
real-world cases (where even if you have a commit graph it might not be
fully up to date), and helps a lot for a worst-case malicious request.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-02-28 14:42:01 -08:00
..
add.c Merge branch 'en/header-cleanup' 2024-01-08 14:05:15 -08:00
am.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
annotate.c
apply.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
archive.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:33 -08:00
bisect.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
blame.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
branch.c branch: make the advice to force-deleting a conditional one 2024-01-11 17:15:54 -08:00
bugreport.c bugreport: reject positional arguments 2023-10-29 08:56:17 +09:00
bundle.c
cat-file.c Merge branch 'js/check-null-from-read-object-file' 2024-02-14 15:36:06 -08:00
check-attr.c check-attr: integrate with sparse-index 2023-08-11 09:44:52 -07:00
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout--worker.c
checkout-index.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
checkout.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
clean.c clean: factorize incompatibility message 2023-12-09 07:41:03 +09:00
clone.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
column.c Merge branch 'rs/column-leakfix' into maint-2.43 2024-02-08 16:22:06 -08:00
commit-graph.c Merge branch 'ja/doc-placeholders-fix' 2024-02-08 13:20:34 -08:00
commit-tree.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
commit.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
config.c config: add back code comment 2024-01-29 10:27:53 -08:00
count-objects.c
credential-cache--daemon.c
credential-cache.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
credential-store.c
credential.c
describe.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
diagnose.c
diff-files.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
diff-index.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
diff-tree.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
diff.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
difftool.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
fast-export.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
fast-import.c fast-import: use mem_pool_calloc() 2023-12-26 11:06:23 -08:00
fetch-pack.c
fetch.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
fmt-merge-msg.c
for-each-ref.c Merge branch 'en/header-cleanup' 2024-01-08 14:05:15 -08:00
for-each-repo.c
fsck.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:33 -08:00
fsmonitor--daemon.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:33 -08:00
gc.c maintenance: use XDG config if it exists 2024-01-18 12:17:42 -08:00
get-tar-commit-id.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
grep.c Merge branch 'js/check-null-from-read-object-file' 2024-02-14 15:36:06 -08:00
hash-object.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
help.c
hook.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
index-pack.c Merge branch 'jk/index-pack-lsan-false-positive-fix' into maint-2.43 2024-02-08 16:22:12 -08:00
init-db.c Merge branch 'ps/refstorage-extension' 2024-01-16 10:11:57 -08:00
interpret-trailers.c Merge branch 'la/trailer-test-and-doc-updates' 2023-10-13 14:18:27 -07:00
log.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
ls-files.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
ls-remote.c Merge branch 'en/header-cleanup' 2024-01-08 14:05:15 -08:00
ls-tree.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
mailinfo.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
mailsplit.c
merge-base.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
merge-file.c merge-file: add --diff-algorithm option 2023-11-22 14:23:06 +09:00
merge-index.c
merge-ours.c
merge-recursive.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
merge-tree.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
merge.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
mktag.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:33 -08:00
mktree.c
multi-pack-index.c
mv.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
name-rev.c name-rev: use OPT_HIDDEN_BOOL for --peel-tag 2023-09-05 14:58:44 -07:00
notes.c Merge branch 'js/check-null-from-read-object-file' 2024-02-14 15:36:06 -08:00
pack-objects.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c
prune.c
pull.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
push.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
range-diff.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
read-tree.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
rebase.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
receive-pack.c receive-pack: use find_commit_header() in check_nonce() 2024-02-12 09:22:20 -08:00
reflog.c Merge branch 'jb/reflog-expire-delete-dry-run-options' into maint-2.43 2024-02-08 16:22:05 -08:00
remote-ext.c
remote-fd.c
remote.c
repack.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
replace.c
replay.c replay: stop assuming replayed branches do not diverge 2023-11-26 10:10:50 +09:00
rerere.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
reset.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
rev-list.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:33 -08:00
rev-parse.c builtin/rev-parse: introduce `--show-ref-format` flag 2024-01-02 09:24:48 -08:00
revert.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
rm.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
send-pack.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
shortlog.c
show-branch.c
show-index.c
show-ref.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
sparse-checkout.c Merge branch 'en/header-cleanup' into maint-2.43 2024-02-08 16:22:10 -08:00
stash.c Merge branch 'ps/report-failure-from-git-stash' 2024-02-12 13:16:11 -08:00
stripspace.c
submodule--helper.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
symbolic-ref.c
tag.c Merge branch 'jc/sign-buffer-failure-propagation-fix' 2024-02-12 13:16:11 -08:00
unpack-file.c
unpack-objects.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
update-index.c Merge branch 'jc/unresolve-removal' 2023-10-02 11:20:00 -07:00
update-ref.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
update-server-info.c
upload-archive.c
upload-pack.c upload-pack: always turn off save_commit_buffer 2024-02-28 14:42:01 -08:00
var.c config: rename global config function 2024-01-18 12:17:41 -08:00
verify-commit.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
verify-pack.c
verify-tag.c treewide: remove unnecessary includes in source files 2023-12-26 12:04:31 -08:00
worktree.c Merge branch 'jc/orphan-unborn' into maint-2.43 2024-02-08 16:22:10 -08:00
write-tree.c