blame: use a size_t for the buffer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/src/blame.c b/src/blame.c
index 56b5b07..404f1f6 100644
--- a/src/blame.c
+++ b/src/blame.c
@@ -268,7 +268,7 @@ static git_blame_hunk *split_hunk_in_vector(
static int index_blob_lines(git_blame *blame)
{
const char *buf = blame->final_buf;
- git_off_t len = blame->final_buf_size;
+ size_t len = blame->final_buf_size;
int num = 0, incomplete = 0, bol = 1;
size_t *i;
@@ -335,8 +335,15 @@ static int blame_internal(git_blame *blame)
if ((error = load_blob(blame)) < 0 ||
(error = git_blame__get_origin(&o, blame, blame->final, blame->path)) < 0)
goto cleanup;
+
+ if (git_blob_rawsize(blame->final_blob) > SIZE_MAX) {
+ git_error_set(GIT_ERROR_NOMEMORY, "blob is too large to blame");
+ error = -1;
+ goto cleanup;
+ }
+
blame->final_buf = git_blob_rawcontent(blame->final_blob);
- blame->final_buf_size = git_blob_rawsize(blame->final_blob);
+ blame->final_buf_size = (size_t)git_blob_rawsize(blame->final_blob);
ent = git__calloc(1, sizeof(git_blame__entry));
GIT_ERROR_CHECK_ALLOC(ent);
diff --git a/src/blame.h b/src/blame.h
index b31d2dc..4141e2b 100644
--- a/src/blame.h
+++ b/src/blame.h
@@ -84,7 +84,7 @@ struct git_blame {
git_blame__entry *ent;
int num_lines;
const char *final_buf;
- git_off_t final_buf_size;
+ size_t final_buf_size;
};
git_blame *git_blame__alloc(