Skip to content

Commit 3db1af1

Browse files
committed
index: error out on unreasonable prefix-compressed path lengths
When computing the complete path length from the encoded prefix-compressed path, we end up just allocating the complete path without ever checking what the encoded path length actually is. This can easily lead to a denial of service by just encoding an unreasonable long path name inside of the index. Git already enforces a maximum path length of 4096 bytes. As we also have that enforcement ready in some places, just make sure that the resulting path is smaller than GIT_PATH_MAX. Reported-by: Krishna Ram Prakash R <krp@gtux.in> Reported-by: Vivek Parikh <viv0411.parikh@gmail.com>
1 parent 3207ddb commit 3db1af1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/index.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,10 @@ static int read_entry(
23792379

23802380
GITERR_CHECK_ALLOC_ADD(&path_len, prefix_len, suffix_len);
23812381
GITERR_CHECK_ALLOC_ADD(&path_len, path_len, 1);
2382+
2383+
if (path_len > GIT_PATH_MAX)
2384+
return index_error_invalid("unreasonable path length");
2385+
23822386
tmp_path = git__malloc(path_len);
23832387
GITERR_CHECK_ALLOC(tmp_path);
23842388

0 commit comments

Comments
 (0)