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_xdiff ignores xdl_diff errors and returns an empty diff #7420
git_xdiff discards the return value of xdl_diff and returns only the error recorded by the hunk/line callbacks:
xdl_diff(&info.xd_old_data, &info.xd_new_data,
&xo->params, &xo->config, &xo->callback); /* 226: result ignored */git_diff_find_context_clear(&findctxt);
returnxo->output.error; /* only set by callbacks */
When xdl_diff fails (for example out of memory while preparing the diff environment or building the edit script),
it returns -1 before any callback runs. xo->output.error stays 0, so git_patch_from_buffers and every other text diff consumer (patch, diff, blame, merge) report success with no hunks.
There is no crash.
Reproduce
05.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 (xdl_malloc is git__malloc). It diffs two small buffers with git_patch_from_buffers, once normally and then with the Nth allocation failing, for N = 1..300, and prints every run that returns 0 with a different hunk count.
All 23 wrong results fail inside xdl_diff (xdl_prepare_env, xdl_do_diff, xdl_build_script). The 5 clean errors come from allocations before xdl_diff and from the hunk/line callbacks, whose errors git_xdiff does return.
Activity