summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-05-20 06:35:11 -0700
committerEdward Thomson <ethomson@edwardthomson.com>2019-06-24 15:00:40 +0100
commit7e49deba90c96fed5779c0c6af2192070db11606 (patch)
tree8af05d75298efa47d2e5ca90ceb489d59d9cff2e /src/index.c
parentd488c02c958ce23947dbd8ec541661192c8be221 (diff)
downloadlibgit2-7e49deba90c96fed5779c0c6af2192070db11606.tar.gz
index: safely cast file size
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/index.c b/src/index.c
index 482728d13..0c90173bc 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1474,6 +1474,11 @@ int git_index_add_from_buffer(
return -1;
}
+ if (len > UINT32_MAX) {
+ git_error_set(GIT_ERROR_INDEX, "buffer is too large");
+ return -1;
+ }
+
if (index_entry_dup(&entry, index, source_entry) < 0)
return -1;
@@ -1484,7 +1489,7 @@ int git_index_add_from_buffer(
}
git_oid_cpy(&entry->id, &id);
- entry->file_size = len;
+ entry->file_size = (uint32_t)len;
if ((error = index_insert(index, &entry, 1, true, true, true)) < 0)
return error;