You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] index_blob_lines error used as a line count #7419
blame_internal stores the return value of index_blob_lines as the line count without checking it:
ent->num_lines=index_blob_lines(blame); /* 454: may be -1 */ent->lno=blame->options.min_line-1;
ent->num_lines=ent->num_lines-blame->options.min_line+1;
index_blob_lines returns -1 when a git_array_alloc fails (GIT_ERROR_CHECK_ALLOC).
The -1 becomes the entry's line count and git_blame_file returns 0,
so the caller gets a successful blame whose hunks add up to (size_t)-1 lines instead of an error.
There is no crash.
Reproduce
04.c installs a counting allocator through GIT_OPT_SET_ALLOCATOR that returns NULL for the Nth allocation, which looks exactly like a real OOM to libgit2. It creates a one-commit repo with a 400-line file.txt, then runs git_blame_file with the Nth allocation failing, for N = 1..1000, and prints every run that returns 0 with a total line count other than 400. The N values depend on the build, which is why the program scans instead of hard-coding them.
Activity