Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c65568d

Browse files
committed
diff: fix OOM on AIX when finding similar deltas in empty diff
The function `git_diff_find_similar` keeps a function of cache similarity metrics signatures, whose size depends on the number of deltas passed in via the `diff` parameter. In case where the diff is empty and thus doesn't have any deltas at all, we may end up allocating this cache via a call to `git__calloc(0, sizeof(void *))`. At least on AIX, allocating 0 bytes will result in a `NULL` pointer being returned, which causes us to erroneously return an OOM error. Fix this situation by simply returning early in case where we are being passed an empty diff, as we cannot find any similarities in that case anyway.
1 parent 9275d84 commit c65568d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/diff_tform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ int git_diff_find_similar(
822822
num_deltas = diff->deltas.length;
823823

824824
/* TODO: maybe abort if deltas.length > rename_limit ??? */
825-
if (!git__is_uint32(num_deltas))
825+
if (!num_deltas || !git__is_uint32(num_deltas))
826826
goto cleanup;
827827

828828
/* No flags set; nothing to do */

0 commit comments

Comments
 (0)