Skip to content

Commit f30e533

Browse files
committed
Merge branch 'jk/cap-exclude-file-size' into maint-2.45
An overly large ".gitignore" files are now rejected silently. * jk/cap-exclude-file-size: dir.c: reduce max pattern file size to 100MB dir.c: skip .gitignore, etc larger than INT_MAX
2 parents ce75d32 + e7c3d1d commit f30e533

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

dir.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "symlinks.h"
3131
#include "trace2.h"
3232
#include "tree.h"
33+
#include "hex.h"
34+
35+
/*
36+
* The maximum size of a pattern/exclude file. If the file exceeds this size
37+
* we will ignore it.
38+
*/
39+
#define PATTERN_MAX_FILE_SIZE (100 * 1024 * 1024)
3340

3441
/*
3542
* Tells read_directory_recursive how a file or directory should be treated.
@@ -1148,6 +1155,12 @@ static int add_patterns(const char *fname, const char *base, int baselen,
11481155
}
11491156
}
11501157

1158+
if (size > PATTERN_MAX_FILE_SIZE) {
1159+
warning("ignoring excessively large pattern file: %s", fname);
1160+
free(buf);
1161+
return -1;
1162+
}
1163+
11511164
add_patterns_from_buffer(buf, size, base, baselen, pl);
11521165
return 0;
11531166
}
@@ -1204,6 +1217,13 @@ int add_patterns_from_blob_to_list(
12041217
if (r != 1)
12051218
return r;
12061219

1220+
if (size > PATTERN_MAX_FILE_SIZE) {
1221+
warning("ignoring excessively large pattern blob: %s",
1222+
oid_to_hex(oid));
1223+
free(buf);
1224+
return -1;
1225+
}
1226+
12071227
add_patterns_from_buffer(buf, size, base, baselen, pl);
12081228
return 0;
12091229
}

t/t0008-ignores.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,4 +945,12 @@ test_expect_success SYMLINKS 'symlinks not respected in-tree' '
945945
test_grep "unable to access.*gitignore" err
946946
'
947947

948+
test_expect_success EXPENSIVE 'large exclude file ignored in tree' '
949+
test_when_finished "rm .gitignore" &&
950+
dd if=/dev/zero of=.gitignore bs=101M count=1 &&
951+
git ls-files -o --exclude-standard 2>err &&
952+
echo "warning: ignoring excessively large pattern file: .gitignore" >expect &&
953+
test_cmp expect err
954+
'
955+
948956
test_done

t/t6112-rev-list-filters-objects.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,16 @@ test_expect_success 'expand blob limit in protocol' '
701701
grep "blob:limit=1024" trace
702702
'
703703

704+
test_expect_success EXPENSIVE 'large sparse filter file ignored' '
705+
blob=$(dd if=/dev/zero bs=101M count=1 |
706+
git hash-object -w --stdin) &&
707+
test_must_fail \
708+
git rev-list --all --objects --filter=sparse:oid=$blob 2>err &&
709+
cat >expect <<-EOF &&
710+
warning: ignoring excessively large pattern blob: $blob
711+
fatal: unable to parse sparse filter data in $blob
712+
EOF
713+
test_cmp expect err
714+
'
715+
704716
test_done

0 commit comments

Comments
 (0)