commit-graph.c: prevent overflow in `split_graph_merge_strategy()`
In a similar spirit as previous commits, ensure that we don't overflow when choosing how to split and merge different layers of the commit-graph. In particular, avoid a potential overflow between `size_mult` and `num_commits`, as well as a potential overflow between the number of commits currently in the merged graph, and the number of commits in the graph about to be merged. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Jul 12, 2023 at 19:38 UTC
19565d093d248ba4c2330d96314a547feed41112
1 file changed
+6
-1
commit-graph.c
+6
-1
@@ -2112,11 +2112,16 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2112
2113
if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED &&
2114
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
2115
- while (g && (g->num_commits <= size_mult * num_commits ||
2115
+ while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
2116
(max_commits && num_commits > max_commits))) {
2117
if (g->odb != ctx->odb)
2118
break;
2119
2120
+ if (unsigned_add_overflows(num_commits, g->num_commits))
2121
+ die(_("cannot merge graphs with %"PRIuMAX", "
2122
+ "%"PRIuMAX" commits"),
2123
+ (uintmax_t)num_commits,
2124
+ (uintmax_t)g->num_commits);
2125
num_commits += g->num_commits;
2126
g = g->base_graph;
2127