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] git_blame_buffer ignores diff errors and returns wrong hunks #7418
git_blame_buffer discards the return value of git_diff_blob_to_buffer and reports success unconditionally:
/* Diff to the reference blob */git_diff_blob_to_buffer(reference->final_blob, blame->path, /* 643: result ignored */buffer, buffer_len, blame->path, &diffopts,
NULL, NULL, buffer_hunk_cb, buffer_line_cb, blame);
*out=blame;
return0; /* 648 */
If the diff fails for any reason (for example out of memory during attribute lookup, patch generation or xdiff), the caller gets 0 and a blame whose hunks do not reflect the buffer, with no way to detect it. There is no crash. The fix is to return the error from git_diff_blob_to_buffer and free the partial blame.
Reproduce
03.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, runs git_blame_file, and records the hunk count of git_blame_buffer on a modified buffer. It then repeats git_blame_buffer with the Nth allocation failing, for N = 1..800, and prints every run that returns 0 with a different hunk count.
The 18 clean errors come from allocations git_blame_buffer does check (git_blame__alloc, dup_hunk). All 63 wrong results come from allocations inside git_diff_blob_to_buffer.
Activity