summaryrefslogtreecommitdiff
path: root/src/diff_generate.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-01-20 22:40:38 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2019-01-25 22:36:38 +0000
commitc6cac733c147ff800f78e7dff81f90d93369ea68 (patch)
tree8defbbcee3413d3524a0a98b6aa3172811e6cf7e /src/diff_generate.c
parent3aa6d96a230d15620df0c6ea2ecaae54f5b49941 (diff)
downloadlibgit2-c6cac733c147ff800f78e7dff81f90d93369ea68.tar.gz
blob: validate that blob sizes fit in a size_t
Our blob size is a `git_off_t`, which is a signed 64 bit int. This may be erroneously negative or larger than `SIZE_MAX`. Ensure that the blob size fits into a `size_t` before casting.
Diffstat (limited to 'src/diff_generate.c')
-rw-r--r--src/diff_generate.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/diff_generate.c b/src/diff_generate.c
index acc6c341b..065cc72a9 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -564,9 +564,14 @@ int git_diff__oid_for_file(
{
git_index_entry entry;
+ if (!git__is_sizet(size)) {
+ git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path);
+ return -1;
+ }
+
memset(&entry, 0, sizeof(entry));
entry.mode = mode;
- entry.file_size = size;
+ entry.file_size = (size_t)size;
entry.path = (char *)path;
return git_diff__oid_for_entry(out, diff, &entry, mode, NULL);
@@ -628,7 +633,7 @@ int git_diff__oid_for_entry(
error = git_odb__hashlink(out, full_path.ptr);
diff->base.perf.oid_calculations++;
} else if (!git__is_sizet(entry.file_size)) {
- git_error_set(GIT_ERROR_OS, "file size overflow (for 32-bits) on '%s'",
+ git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'",
entry.path);
error = -1;
} else if (!(error = git_filter_list_load(&fl,