From 501cf47cddfbf8040b6f9b8ac06d13094a70f729 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Wed, 3 Jun 2015 15:51:59 +0200 Subject: read_loose_refs(): treat NULL_SHA1 loose references as broken NULL_SHA1 is used to indicate an "invalid object name" throughout our code (and the code of other git implementations), so it is vastly more likely that an on-disk reference was set to this value due to a software bug than that NULL_SHA1 is the legitimate SHA-1 of an actual object. Therefore, if a loose reference has the value NULL_SHA1, consider it to be broken. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- refs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'refs.c') diff --git a/refs.c b/refs.c index 3c311d44c1..07f8847e6d 100644 --- a/refs.c +++ b/refs.c @@ -1297,6 +1297,16 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir) if (!read_ok) { hashclr(sha1); flag |= REF_ISBROKEN; + } else if (is_null_sha1(sha1)) { + /* + * It is so astronomically unlikely + * that NULL_SHA1 is the SHA-1 of an + * actual object that we consider its + * appearance in a loose reference + * file to be repo corruption + * (probably due to a software bug). + */ + flag |= REF_ISBROKEN; } if (check_refname_format(refname.buf, -- cgit v1.2.1