summaryrefslogtreecommitdiff
path: root/src/attr_file.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/attr_file.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/attr_file.c')
-rw-r--r--src/attr_file.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index bd69c631b..40c72ea04 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -12,6 +12,7 @@
#include "attrcache.h"
#include "git2/blob.h"
#include "git2/tree.h"
+#include "blob.h"
#include "index.h"
#include <ctype.h>
@@ -119,6 +120,7 @@ int git_attr_file__load(
break;
case GIT_ATTR_FILE__FROM_INDEX: {
git_oid id;
+ git_off_t blobsize;
if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
(error = git_blob_lookup(&blob, repo, &id)) < 0)
@@ -126,7 +128,10 @@ int git_attr_file__load(
/* Do not assume that data straight from the ODB is NULL-terminated;
* copy the contents of a file to a buffer to work on */
- git_buf_put(&content, git_blob_rawcontent(blob), git_blob_rawsize(blob));
+ blobsize = git_blob_rawsize(blob);
+
+ GIT_ERROR_CHECK_BLOBSIZE(blobsize);
+ git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
break;
}
case GIT_ATTR_FILE__FROM_FILE: {