diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2019-01-20 22:40:38 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-01-25 22:36:38 +0000 |
commit | c6cac733c147ff800f78e7dff81f90d93369ea68 (patch) | |
tree | 8defbbcee3413d3524a0a98b6aa3172811e6cf7e /src/blob.h | |
parent | 3aa6d96a230d15620df0c6ea2ecaae54f5b49941 (diff) | |
download | libgit2-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/blob.h')
-rw-r--r-- | src/blob.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/blob.h b/src/blob.h index f644ec583..b9aa33004 100644 --- a/src/blob.h +++ b/src/blob.h @@ -27,6 +27,14 @@ struct git_blob { unsigned int raw:1; }; +#define GIT_ERROR_CHECK_BLOBSIZE(n) \ + do { \ + if (!git__is_sizet(n)) { \ + git_error_set(GIT_ERROR_NOMEMORY, "blob contents too large to fit in memory"); \ + return -1; \ + } \ + } while(0) + void git_blob__free(void *blob); int git_blob__parse(void *blob, git_odb_object *obj); int git_blob__parse_raw(void *blob, const char *data, size_t size); |