]> git.ipfire.org Git - thirdparty/git.git/commit - attr.h
attr: ignore overly large gitattributes files
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Dec 2022 14:45:53 +0000 (15:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2022 06:50:03 +0000 (15:50 +0900)
commit3c50032ff5289cc45659f21949c8d09e52164579
tree2d9a9379e7d94be5d8ad773466c90a76b79034d5
parentdfa6b32b5e599d97448337ed4fc18dd50c90758f
attr: ignore overly large gitattributes files

Similar as with the preceding commit, start ignoring gitattributes files
that are overly large to protect us against out-of-bounds reads and
writes caused by integer overflows. Unfortunately, we cannot just define
"overly large" in terms of any preexisting limits in the codebase.

Instead, we choose a very conservative limit of 100MB. This is plenty of
room for specifying gitattributes, and incidentally it is also the limit
for blob sizes for GitHub. While we don't want GitHub to dictate limits
here, it is still sensible to use this fact for an informed decision
given that it is hosting a huge set of repositories. Furthermore, over
at GitLab we scanned a subset of repositories for their root-level
attribute files. We found that 80% of them have a gitattributes file
smaller than 100kB, 99.99% have one smaller than 1MB, and only a single
repository had one that was almost 3MB in size. So enforcing a limit of
100MB seems to give us ample of headroom.

With this limit in place we can be reasonably sure that there is no easy
way to exploit the gitattributes file via integer overflows anymore.
Furthermore, it protects us against resource exhaustion caused by
allocating the in-memory data structures required to represent the
parsed attributes.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c
attr.h
t/t0003-attributes.sh