Skip to content

Commit 3e6533b

Browse files
committed
odb_loose: reject objects that cannot fit in memory
Check the size of objects being read from the loose odb backend and reject those that would not fit in memory with an error message that reflects the actual problem, instead of error'ing later with an unintuitive error message regarding truncation or invalid hashes.
1 parent 8642feb commit 3e6533b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/odb_loose.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ static int parse_header(
156156
size < 0)
157157
goto on_error;
158158

159+
if ((uint64_t)size > SIZE_MAX) {
160+
giterr_set(GITERR_OBJECT, "object is larger than available memory");
161+
return -1;
162+
}
163+
159164
out->size = size;
160165

161166
if (GIT_ADD_SIZET_OVERFLOW(out_len, i, 1))

tests/odb/largefiles.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,24 @@ void test_odb_largefiles__read_into_memory(void)
9393

9494
git_odb_object_free(obj);
9595
}
96+
97+
void test_odb_largefiles__read_into_memory_rejected_on_32bit(void)
98+
{
99+
git_oid oid;
100+
git_odb_object *obj = NULL;
101+
102+
#ifdef GIT_ARCH_64
103+
cl_skip();
104+
#endif
105+
106+
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
107+
cl_skip();
108+
109+
if (!cl_is_env_set("GITTEST_INVASIVE_MEMORY"))
110+
cl_skip();
111+
112+
writefile(&oid);
113+
cl_git_fail(git_odb_read(&obj, odb, &oid));
114+
115+
git_odb_object_free(obj);
116+
}

0 commit comments

Comments
 (0)