]> git.ipfire.org Git - thirdparty/git.git/commit - attr.c
attr: fix silently splitting up lines longer than 2048 bytes
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Dec 2022 14:45:44 +0000 (15:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2022 06:29:30 +0000 (15:29 +0900)
commitd74b1fd54fdbc45966d12ea907dece11e072fb2b
tree01ec181347a97870e297417330393c639475c25a
parenta60a66e409c265b2944f18bf43581c146812586d
attr: fix silently splitting up lines longer than 2048 bytes

When reading attributes from a file we use fgets(3P) with a buffer size
of 2048 bytes. This means that as soon as a line exceeds the buffer size
we split it up into multiple parts and parse each of them as a separate
pattern line. This is of course not what the user intended, and even
worse the behaviour is inconsistent with how we read attributes from the
index.

Fix this bug by converting the code to use `strbuf_getline()` instead.
This will indeed read in the whole line, which may theoretically lead to
an out-of-memory situation when the gitattributes file is huge. We're
about to reject any gitattributes files larger than 100MB in the next
commit though, which makes this less of a concern.

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