Commit 5d44cd1c authored by Linus Torvalds's avatar Linus Torvalds Committed by Junio C Hamano

Fix git-fsck-objects SIGSEGV/divide-by-zero

If you try to fsck a repository that isn't entirely empty, but that has no
inter-object references (ie all the objects are blobs, and don't refer to
anything else), git-fsck-objects currently fails.

This probably cannot happen in practice, but can be tested with something

	git init-db
	touch dummy
	git add dummy
	git fsck-objects

where the fsck will die by a divide-by-zero when it tries to look up the
references from the one object it found (hash_obj() will do a modulus by

On some other archiectures (ppc, sparc) the divide-by-zero will go
unnoticed, and we'll instead SIGSEGV when we hit the "refs_hash[j]"

So move the test that should protect against this from mark_reachable()
into lookup_object_refs(), which incidentally in the process also fixes
mark_reachable() itself (it used to not mark the one object that _was_
reachable, because it decided that it had no refs too early).
Signed-off-by: default avatarLinus Torvalds <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent f2e60947
......@@ -55,9 +55,13 @@ static void add_object_refs(struct object *obj, struct object_refs *ref)
struct object_refs *lookup_object_refs(struct object *obj)
int j = hash_obj(obj, refs_hash_size);
struct object_refs *ref;
int j;
/* nothing to lookup */
if (!refs_hash_size)
return NULL;
j = hash_obj(obj, refs_hash_size);
while ((ref = refs_hash[j]) != NULL) {
if (ref->base == obj)
......@@ -125,9 +129,6 @@ void mark_reachable(struct object *obj, unsigned int mask)
if (!track_object_refs)
die("cannot do reachability with object refs turned off");
/* nothing to lookup */
if (!refs_hash_size)
/* If we've been here already, don't bother */
if (obj->flags & mask)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment