summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2017-12-10 17:25:00 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2017-12-20 16:08:04 +0000
commit3e6533ba12c1c567f91efe621bdd155ff801877c (patch)
treeb30161e03a265bcf082d21f7daf03d7260008e2b
parent8642feba7429ac2941a879a0870a84a83a3664cd (diff)
downloadlibgit2-3e6533ba12c1c567f91efe621bdd155ff801877c.tar.gz
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.
-rw-r--r--src/odb_loose.c5
-rw-r--r--tests/odb/largefiles.c21
2 files changed, 26 insertions, 0 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 2294931b4..9900aae2a 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -156,6 +156,11 @@ static int parse_header(
size < 0)
goto on_error;
+ if ((uint64_t)size > SIZE_MAX) {
+ giterr_set(GITERR_OBJECT, "object is larger than available memory");
+ return -1;
+ }
+
out->size = size;
if (GIT_ADD_SIZET_OVERFLOW(out_len, i, 1))
diff --git a/tests/odb/largefiles.c b/tests/odb/largefiles.c
index 9a91cf1f0..dc987c473 100644
--- a/tests/odb/largefiles.c
+++ b/tests/odb/largefiles.c
@@ -93,3 +93,24 @@ void test_odb_largefiles__read_into_memory(void)
git_odb_object_free(obj);
}
+
+void test_odb_largefiles__read_into_memory_rejected_on_32bit(void)
+{
+ git_oid oid;
+ git_odb_object *obj = NULL;
+
+#ifdef GIT_ARCH_64
+ cl_skip();
+#endif
+
+ if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
+ cl_skip();
+
+ if (!cl_is_env_set("GITTEST_INVASIVE_MEMORY"))
+ cl_skip();
+
+ writefile(&oid);
+ cl_git_fail(git_odb_read(&obj, odb, &oid));
+
+ git_odb_object_free(obj);
+}