Skip to content

Commit 1bf173c

Browse files
authored
Merge pull request libgit2#4431 from lhchavez/fix-stream-leak
libFuzzer: Fix a git_packfile_stream leak
2 parents 429bb35 + 400caed commit 1bf173c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/indexer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,9 @@ void git_indexer_free(git_indexer *idx)
11191119
if (idx == NULL)
11201120
return;
11211121

1122+
if (idx->have_stream)
1123+
git_packfile_stream_free(&idx->stream);
1124+
11221125
git_vector_free_deep(&idx->objects);
11231126

11241127
if (idx->pack->idx_cache) {

tests/pack/indexer.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ static const unsigned char thin_pack[] = {
4040
};
4141
static const unsigned int thin_pack_len = 78;
4242

43+
/*
44+
* Packfile that causes the packfile stream to open in a way in which it leaks
45+
* the stream reader.
46+
*/
47+
static const unsigned char leaky_pack[] = {
48+
0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
49+
0xf4, 0xbd, 0x51, 0x51, 0x51, 0x51, 0x51, 0x72, 0x65, 0x41, 0x4b, 0x63,
50+
0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0xbd, 0x41, 0x4b
51+
};
52+
static const unsigned int leaky_pack_len = 33;
53+
4354
static const unsigned char base_obj[] = { 07, 076 };
4455
static const unsigned int base_obj_len = 2;
4556

@@ -60,6 +71,22 @@ void test_pack_indexer__out_of_order(void)
6071
git_indexer_free(idx);
6172
}
6273

74+
void test_pack_indexer__leaky(void)
75+
{
76+
git_indexer *idx = 0;
77+
git_transfer_progress stats = { 0 };
78+
79+
cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL, NULL));
80+
cl_git_pass(git_indexer_append(
81+
idx, leaky_pack, leaky_pack_len, &stats));
82+
cl_git_fail(git_indexer_commit(idx, &stats));
83+
84+
cl_assert(giterr_last() != NULL);
85+
cl_assert_equal_i(giterr_last()->klass, GITERR_INDEXER);
86+
87+
git_indexer_free(idx);
88+
}
89+
6390
void test_pack_indexer__fix_thin(void)
6491
{
6592
git_indexer *idx = NULL;

0 commit comments

Comments
 (0)