vendor/libgit2/src/blame.c in rugged-0.28.5 vs vendor/libgit2/src/blame.c in rugged-0.99.0

- old
+ new

@@ -202,11 +202,11 @@ if (!in) in = &dummy; memcpy(out, in, sizeof(git_blame_options)); /* No newest_commit => HEAD */ - if (git_oid_iszero(&out->newest_commit)) { + if (git_oid_is_zero(&out->newest_commit)) { if (git_reference_name_to_id(&out->newest_commit, repo, "HEAD") < 0) { return -1; } } @@ -266,11 +266,11 @@ * https://github.com/gitster/git/blob/be5c9fb9049ed470e7005f159bb923a5f4de1309/builtin/blame.c#L1760-L1789 */ 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; if (len && buf[len-1] != '\n') incomplete++; /* incomplete line at the end */ @@ -333,12 +333,19 @@ git_blame__origin *o; 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); ent->num_lines = index_blob_lines(blame); @@ -406,11 +413,11 @@ * Buffer blaming *******************************************************************************/ static bool hunk_is_bufferblame(git_blame_hunk *hunk) { - return hunk && git_oid_iszero(&hunk->final_commit_id); + return git_oid_is_zero(&hunk->final_commit_id); } static int buffer_hunk_cb( const git_diff_delta *delta, const git_diff_hunk *hunk, @@ -522,11 +529,16 @@ *out = blame; return 0; } -int git_blame_init_options(git_blame_options *opts, unsigned int version) +int git_blame_options_init(git_blame_options *opts, unsigned int version) { GIT_INIT_STRUCTURE_FROM_TEMPLATE( opts, version, git_blame_options, GIT_BLAME_OPTIONS_INIT); return 0; +} + +int git_blame_init_options(git_blame_options *opts, unsigned int version) +{ + return git_blame_options_init(opts, version); }