Skip to content

Commit 8348766

Browse files
peffttaylorr
authored andcommitted
get_commit_tree(): return NULL for broken tree
Return NULL from 'get_commit_tree()' when a commit's root tree is corrupt, doesn't exist, or points to an object which is not a tree. In [1], this situation became a BUG(), but it can certainly occur in cases which are not a bug in Git, for e.g., if a caller manually crafts a commit whose tree is corrupt in any of the above ways. Note that the expect_failure test in t6102 triggers this BUG(), but we can't flip it to expect_success yet. Solving this problem actually reveals a second bug. [1]: 7b8a21d (commit-graph: lazy-load trees for commits, 2018-04-06) Co-authored-by: Taylor Blau <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b49e74e commit 8348766

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

commit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ struct tree *get_commit_tree(const struct commit *commit)
345345
if (commit->maybe_tree || !commit->object.parsed)
346346
return commit->maybe_tree;
347347

348-
if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
349-
BUG("commit has NULL tree, but was not loaded from commit-graph");
348+
if (commit->graph_pos != COMMIT_NOT_FROM_GRAPH)
349+
return get_commit_tree_in_graph(the_repository, commit);
350350

351-
return get_commit_tree_in_graph(the_repository, commit);
351+
return NULL;
352352
}
353353

354354
struct object_id *get_commit_tree_oid(const struct commit *commit)

0 commit comments

Comments
 (0)