30c1a19aa583a4093fa6b9e2d2f6a6a7842e0b00
   1#include "cache.h"
   2#include "object.h"
   3#include "blob.h"
   4#include "tree.h"
   5#include "tree-walk.h"
   6#include "commit.h"
   7#include "tag.h"
   8#include "fsck.h"
   9#include "refs.h"
  10#include "utf8.h"
  11
  12#define FOREACH_MSG_ID(FUNC) \
  13        /* errors */ \
  14        FUNC(BAD_DATE, ERROR) \
  15        FUNC(BAD_DATE_OVERFLOW, ERROR) \
  16        FUNC(BAD_EMAIL, ERROR) \
  17        FUNC(BAD_NAME, ERROR) \
  18        FUNC(BAD_OBJECT_SHA1, ERROR) \
  19        FUNC(BAD_PARENT_SHA1, ERROR) \
  20        FUNC(BAD_TAG_OBJECT, ERROR) \
  21        FUNC(BAD_TIMEZONE, ERROR) \
  22        FUNC(BAD_TREE, ERROR) \
  23        FUNC(BAD_TREE_SHA1, ERROR) \
  24        FUNC(BAD_TYPE, ERROR) \
  25        FUNC(DUPLICATE_ENTRIES, ERROR) \
  26        FUNC(MISSING_AUTHOR, ERROR) \
  27        FUNC(MISSING_COMMITTER, ERROR) \
  28        FUNC(MISSING_EMAIL, ERROR) \
  29        FUNC(MISSING_GRAFT, ERROR) \
  30        FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
  31        FUNC(MISSING_OBJECT, ERROR) \
  32        FUNC(MISSING_PARENT, ERROR) \
  33        FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
  34        FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
  35        FUNC(MISSING_TAG, ERROR) \
  36        FUNC(MISSING_TAG_ENTRY, ERROR) \
  37        FUNC(MISSING_TAG_OBJECT, ERROR) \
  38        FUNC(MISSING_TREE, ERROR) \
  39        FUNC(MISSING_TYPE, ERROR) \
  40        FUNC(MISSING_TYPE_ENTRY, ERROR) \
  41        FUNC(NUL_IN_HEADER, ERROR) \
  42        FUNC(TAG_OBJECT_NOT_TAG, ERROR) \
  43        FUNC(TREE_NOT_SORTED, ERROR) \
  44        FUNC(UNKNOWN_TYPE, ERROR) \
  45        FUNC(UNTERMINATED_HEADER, ERROR) \
  46        FUNC(ZERO_PADDED_DATE, ERROR) \
  47        /* warnings */ \
  48        FUNC(BAD_FILEMODE, WARN) \
  49        FUNC(BAD_TAG_NAME, WARN) \
  50        FUNC(EMPTY_NAME, WARN) \
  51        FUNC(FULL_PATHNAME, WARN) \
  52        FUNC(HAS_DOT, WARN) \
  53        FUNC(HAS_DOTDOT, WARN) \
  54        FUNC(HAS_DOTGIT, WARN) \
  55        FUNC(MISSING_TAGGER_ENTRY, WARN) \
  56        FUNC(NULL_SHA1, WARN) \
  57        FUNC(ZERO_PADDED_FILEMODE, WARN)
  58
  59#define MSG_ID(id, msg_type) FSCK_MSG_##id,
  60enum fsck_msg_id {
  61        FOREACH_MSG_ID(MSG_ID)
  62        FSCK_MSG_MAX
  63};
  64#undef MSG_ID
  65
  66#define STR(x) #x
  67#define MSG_ID(id, msg_type) { STR(id), NULL, FSCK_##msg_type },
  68static struct {
  69        const char *id_string;
  70        const char *downcased;
  71        int msg_type;
  72} msg_id_info[FSCK_MSG_MAX + 1] = {
  73        FOREACH_MSG_ID(MSG_ID)
  74        { NULL, NULL, -1 }
  75};
  76#undef MSG_ID
  77
  78static int parse_msg_id(const char *text)
  79{
  80        int i;
  81
  82        if (!msg_id_info[0].downcased) {
  83                /* convert id_string to lower case, without underscores. */
  84                for (i = 0; i < FSCK_MSG_MAX; i++) {
  85                        const char *p = msg_id_info[i].id_string;
  86                        int len = strlen(p);
  87                        char *q = xmalloc(len);
  88
  89                        msg_id_info[i].downcased = q;
  90                        while (*p)
  91                                if (*p == '_')
  92                                        p++;
  93                                else
  94                                        *(q)++ = tolower(*(p)++);
  95                        *q = '\0';
  96                }
  97        }
  98
  99        for (i = 0; i < FSCK_MSG_MAX; i++)
 100                if (!strcmp(text, msg_id_info[i].downcased))
 101                        return i;
 102
 103        return -1;
 104}
 105
 106static int fsck_msg_type(enum fsck_msg_id msg_id,
 107        struct fsck_options *options)
 108{
 109        int msg_type;
 110
 111        msg_type = msg_id_info[msg_id].msg_type;
 112        if (options->strict && msg_type == FSCK_WARN)
 113                msg_type = FSCK_ERROR;
 114
 115        return msg_type;
 116}
 117
 118__attribute__((format (printf, 4, 5)))
 119static int report(struct fsck_options *options, struct object *object,
 120        enum fsck_msg_id id, const char *fmt, ...)
 121{
 122        va_list ap;
 123        struct strbuf sb = STRBUF_INIT;
 124        int msg_type = fsck_msg_type(id, options), result;
 125
 126        va_start(ap, fmt);
 127        strbuf_vaddf(&sb, fmt, ap);
 128        result = options->error_func(object, msg_type, sb.buf);
 129        strbuf_release(&sb);
 130        va_end(ap);
 131
 132        return result;
 133}
 134
 135static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *options)
 136{
 137        struct tree_desc desc;
 138        struct name_entry entry;
 139        int res = 0;
 140
 141        if (parse_tree(tree))
 142                return -1;
 143
 144        init_tree_desc(&desc, tree->buffer, tree->size);
 145        while (tree_entry(&desc, &entry)) {
 146                int result;
 147
 148                if (S_ISGITLINK(entry.mode))
 149                        continue;
 150                if (S_ISDIR(entry.mode))
 151                        result = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);
 152                else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))
 153                        result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
 154                else {
 155                        result = error("in tree %s: entry %s has bad mode %.6o",
 156                                        sha1_to_hex(tree->object.sha1), entry.path, entry.mode);
 157                }
 158                if (result < 0)
 159                        return result;
 160                if (!res)
 161                        res = result;
 162        }
 163        return res;
 164}
 165
 166static int fsck_walk_commit(struct commit *commit, void *data, struct fsck_options *options)
 167{
 168        struct commit_list *parents;
 169        int res;
 170        int result;
 171
 172        if (parse_commit(commit))
 173                return -1;
 174
 175        result = options->walk((struct object *)commit->tree, OBJ_TREE, data, options);
 176        if (result < 0)
 177                return result;
 178        res = result;
 179
 180        parents = commit->parents;
 181        while (parents) {
 182                result = options->walk((struct object *)parents->item, OBJ_COMMIT, data, options);
 183                if (result < 0)
 184                        return result;
 185                if (!res)
 186                        res = result;
 187                parents = parents->next;
 188        }
 189        return res;
 190}
 191
 192static int fsck_walk_tag(struct tag *tag, void *data, struct fsck_options *options)
 193{
 194        if (parse_tag(tag))
 195                return -1;
 196        return options->walk(tag->tagged, OBJ_ANY, data, options);
 197}
 198
 199int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
 200{
 201        if (!obj)
 202                return -1;
 203        switch (obj->type) {
 204        case OBJ_BLOB:
 205                return 0;
 206        case OBJ_TREE:
 207                return fsck_walk_tree((struct tree *)obj, data, options);
 208        case OBJ_COMMIT:
 209                return fsck_walk_commit((struct commit *)obj, data, options);
 210        case OBJ_TAG:
 211                return fsck_walk_tag((struct tag *)obj, data, options);
 212        default:
 213                error("Unknown object type for %s", sha1_to_hex(obj->sha1));
 214                return -1;
 215        }
 216}
 217
 218/*
 219 * The entries in a tree are ordered in the _path_ order,
 220 * which means that a directory entry is ordered by adding
 221 * a slash to the end of it.
 222 *
 223 * So a directory called "a" is ordered _after_ a file
 224 * called "a.c", because "a/" sorts after "a.c".
 225 */
 226#define TREE_UNORDERED (-1)
 227#define TREE_HAS_DUPS  (-2)
 228
 229static int verify_ordered(unsigned mode1, const char *name1, unsigned mode2, const char *name2)
 230{
 231        int len1 = strlen(name1);
 232        int len2 = strlen(name2);
 233        int len = len1 < len2 ? len1 : len2;
 234        unsigned char c1, c2;
 235        int cmp;
 236
 237        cmp = memcmp(name1, name2, len);
 238        if (cmp < 0)
 239                return 0;
 240        if (cmp > 0)
 241                return TREE_UNORDERED;
 242
 243        /*
 244         * Ok, the first <len> characters are the same.
 245         * Now we need to order the next one, but turn
 246         * a '\0' into a '/' for a directory entry.
 247         */
 248        c1 = name1[len];
 249        c2 = name2[len];
 250        if (!c1 && !c2)
 251                /*
 252                 * git-write-tree used to write out a nonsense tree that has
 253                 * entries with the same name, one blob and one tree.  Make
 254                 * sure we do not have duplicate entries.
 255                 */
 256                return TREE_HAS_DUPS;
 257        if (!c1 && S_ISDIR(mode1))
 258                c1 = '/';
 259        if (!c2 && S_ISDIR(mode2))
 260                c2 = '/';
 261        return c1 < c2 ? 0 : TREE_UNORDERED;
 262}
 263
 264static int fsck_tree(struct tree *item, struct fsck_options *options)
 265{
 266        int retval;
 267        int has_null_sha1 = 0;
 268        int has_full_path = 0;
 269        int has_empty_name = 0;
 270        int has_dot = 0;
 271        int has_dotdot = 0;
 272        int has_dotgit = 0;
 273        int has_zero_pad = 0;
 274        int has_bad_modes = 0;
 275        int has_dup_entries = 0;
 276        int not_properly_sorted = 0;
 277        struct tree_desc desc;
 278        unsigned o_mode;
 279        const char *o_name;
 280
 281        init_tree_desc(&desc, item->buffer, item->size);
 282
 283        o_mode = 0;
 284        o_name = NULL;
 285
 286        while (desc.size) {
 287                unsigned mode;
 288                const char *name;
 289                const unsigned char *sha1;
 290
 291                sha1 = tree_entry_extract(&desc, &name, &mode);
 292
 293                has_null_sha1 |= is_null_sha1(sha1);
 294                has_full_path |= !!strchr(name, '/');
 295                has_empty_name |= !*name;
 296                has_dot |= !strcmp(name, ".");
 297                has_dotdot |= !strcmp(name, "..");
 298                has_dotgit |= (!strcmp(name, ".git") ||
 299                               is_hfs_dotgit(name) ||
 300                               is_ntfs_dotgit(name));
 301                has_zero_pad |= *(char *)desc.buffer == '0';
 302                update_tree_entry(&desc);
 303
 304                switch (mode) {
 305                /*
 306                 * Standard modes..
 307                 */
 308                case S_IFREG | 0755:
 309                case S_IFREG | 0644:
 310                case S_IFLNK:
 311                case S_IFDIR:
 312                case S_IFGITLINK:
 313                        break;
 314                /*
 315                 * This is nonstandard, but we had a few of these
 316                 * early on when we honored the full set of mode
 317                 * bits..
 318                 */
 319                case S_IFREG | 0664:
 320                        if (!options->strict)
 321                                break;
 322                default:
 323                        has_bad_modes = 1;
 324                }
 325
 326                if (o_name) {
 327                        switch (verify_ordered(o_mode, o_name, mode, name)) {
 328                        case TREE_UNORDERED:
 329                                not_properly_sorted = 1;
 330                                break;
 331                        case TREE_HAS_DUPS:
 332                                has_dup_entries = 1;
 333                                break;
 334                        default:
 335                                break;
 336                        }
 337                }
 338
 339                o_mode = mode;
 340                o_name = name;
 341        }
 342
 343        retval = 0;
 344        if (has_null_sha1)
 345                retval += report(options, &item->object, FSCK_MSG_NULL_SHA1, "contains entries pointing to null sha1");
 346        if (has_full_path)
 347                retval += report(options, &item->object, FSCK_MSG_FULL_PATHNAME, "contains full pathnames");
 348        if (has_empty_name)
 349                retval += report(options, &item->object, FSCK_MSG_EMPTY_NAME, "contains empty pathname");
 350        if (has_dot)
 351                retval += report(options, &item->object, FSCK_MSG_HAS_DOT, "contains '.'");
 352        if (has_dotdot)
 353                retval += report(options, &item->object, FSCK_MSG_HAS_DOTDOT, "contains '..'");
 354        if (has_dotgit)
 355                retval += report(options, &item->object, FSCK_MSG_HAS_DOTGIT, "contains '.git'");
 356        if (has_zero_pad)
 357                retval += report(options, &item->object, FSCK_MSG_ZERO_PADDED_FILEMODE, "contains zero-padded file modes");
 358        if (has_bad_modes)
 359                retval += report(options, &item->object, FSCK_MSG_BAD_FILEMODE, "contains bad file modes");
 360        if (has_dup_entries)
 361                retval += report(options, &item->object, FSCK_MSG_DUPLICATE_ENTRIES, "contains duplicate file entries");
 362        if (not_properly_sorted)
 363                retval += report(options, &item->object, FSCK_MSG_TREE_NOT_SORTED, "not properly sorted");
 364        return retval;
 365}
 366
 367static int require_end_of_header(const void *data, unsigned long size,
 368        struct object *obj, struct fsck_options *options)
 369{
 370        const char *buffer = (const char *)data;
 371        unsigned long i;
 372
 373        for (i = 0; i < size; i++) {
 374                switch (buffer[i]) {
 375                case '\0':
 376                        return report(options, obj,
 377                                FSCK_MSG_NUL_IN_HEADER,
 378                                "unterminated header: NUL at offset %ld", i);
 379                case '\n':
 380                        if (i + 1 < size && buffer[i + 1] == '\n')
 381                                return 0;
 382                }
 383        }
 384
 385        return report(options, obj,
 386                FSCK_MSG_UNTERMINATED_HEADER, "unterminated header");
 387}
 388
 389static int fsck_ident(const char **ident, struct object *obj, struct fsck_options *options)
 390{
 391        char *end;
 392
 393        if (**ident == '<')
 394                return report(options, obj, FSCK_MSG_MISSING_NAME_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
 395        *ident += strcspn(*ident, "<>\n");
 396        if (**ident == '>')
 397                return report(options, obj, FSCK_MSG_BAD_NAME, "invalid author/committer line - bad name");
 398        if (**ident != '<')
 399                return report(options, obj, FSCK_MSG_MISSING_EMAIL, "invalid author/committer line - missing email");
 400        if ((*ident)[-1] != ' ')
 401                return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_EMAIL, "invalid author/committer line - missing space before email");
 402        (*ident)++;
 403        *ident += strcspn(*ident, "<>\n");
 404        if (**ident != '>')
 405                return report(options, obj, FSCK_MSG_BAD_EMAIL, "invalid author/committer line - bad email");
 406        (*ident)++;
 407        if (**ident != ' ')
 408                return report(options, obj, FSCK_MSG_MISSING_SPACE_BEFORE_DATE, "invalid author/committer line - missing space before date");
 409        (*ident)++;
 410        if (**ident == '0' && (*ident)[1] != ' ')
 411                return report(options, obj, FSCK_MSG_ZERO_PADDED_DATE, "invalid author/committer line - zero-padded date");
 412        if (date_overflows(strtoul(*ident, &end, 10)))
 413                return report(options, obj, FSCK_MSG_BAD_DATE_OVERFLOW, "invalid author/committer line - date causes integer overflow");
 414        if (end == *ident || *end != ' ')
 415                return report(options, obj, FSCK_MSG_BAD_DATE, "invalid author/committer line - bad date");
 416        *ident = end + 1;
 417        if ((**ident != '+' && **ident != '-') ||
 418            !isdigit((*ident)[1]) ||
 419            !isdigit((*ident)[2]) ||
 420            !isdigit((*ident)[3]) ||
 421            !isdigit((*ident)[4]) ||
 422            ((*ident)[5] != '\n'))
 423                return report(options, obj, FSCK_MSG_BAD_TIMEZONE, "invalid author/committer line - bad time zone");
 424        (*ident) += 6;
 425        return 0;
 426}
 427
 428static int fsck_commit_buffer(struct commit *commit, const char *buffer,
 429        unsigned long size, struct fsck_options *options)
 430{
 431        unsigned char tree_sha1[20], sha1[20];
 432        struct commit_graft *graft;
 433        unsigned parent_count, parent_line_count = 0;
 434        int err;
 435
 436        if (require_end_of_header(buffer, size, &commit->object, options))
 437                return -1;
 438
 439        if (!skip_prefix(buffer, "tree ", &buffer))
 440                return report(options, &commit->object, FSCK_MSG_MISSING_TREE, "invalid format - expected 'tree' line");
 441        if (get_sha1_hex(buffer, tree_sha1) || buffer[40] != '\n')
 442                return report(options, &commit->object, FSCK_MSG_BAD_TREE_SHA1, "invalid 'tree' line format - bad sha1");
 443        buffer += 41;
 444        while (skip_prefix(buffer, "parent ", &buffer)) {
 445                if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n')
 446                        return report(options, &commit->object, FSCK_MSG_BAD_PARENT_SHA1, "invalid 'parent' line format - bad sha1");
 447                buffer += 41;
 448                parent_line_count++;
 449        }
 450        graft = lookup_commit_graft(commit->object.sha1);
 451        parent_count = commit_list_count(commit->parents);
 452        if (graft) {
 453                if (graft->nr_parent == -1 && !parent_count)
 454                        ; /* shallow commit */
 455                else if (graft->nr_parent != parent_count)
 456                        return report(options, &commit->object, FSCK_MSG_MISSING_GRAFT, "graft objects missing");
 457        } else {
 458                if (parent_count != parent_line_count)
 459                        return report(options, &commit->object, FSCK_MSG_MISSING_PARENT, "parent objects missing");
 460        }
 461        if (!skip_prefix(buffer, "author ", &buffer))
 462                return report(options, &commit->object, FSCK_MSG_MISSING_AUTHOR, "invalid format - expected 'author' line");
 463        err = fsck_ident(&buffer, &commit->object, options);
 464        if (err)
 465                return err;
 466        if (!skip_prefix(buffer, "committer ", &buffer))
 467                return report(options, &commit->object, FSCK_MSG_MISSING_COMMITTER, "invalid format - expected 'committer' line");
 468        err = fsck_ident(&buffer, &commit->object, options);
 469        if (err)
 470                return err;
 471        if (!commit->tree)
 472                return report(options, &commit->object, FSCK_MSG_BAD_TREE, "could not load commit's tree %s", sha1_to_hex(tree_sha1));
 473
 474        return 0;
 475}
 476
 477static int fsck_commit(struct commit *commit, const char *data,
 478        unsigned long size, struct fsck_options *options)
 479{
 480        const char *buffer = data ?  data : get_commit_buffer(commit, &size);
 481        int ret = fsck_commit_buffer(commit, buffer, size, options);
 482        if (!data)
 483                unuse_commit_buffer(commit, buffer);
 484        return ret;
 485}
 486
 487static int fsck_tag_buffer(struct tag *tag, const char *data,
 488        unsigned long size, struct fsck_options *options)
 489{
 490        unsigned char sha1[20];
 491        int ret = 0;
 492        const char *buffer;
 493        char *to_free = NULL, *eol;
 494        struct strbuf sb = STRBUF_INIT;
 495
 496        if (data)
 497                buffer = data;
 498        else {
 499                enum object_type type;
 500
 501                buffer = to_free =
 502                        read_sha1_file(tag->object.sha1, &type, &size);
 503                if (!buffer)
 504                        return report(options, &tag->object,
 505                                FSCK_MSG_MISSING_TAG_OBJECT,
 506                                "cannot read tag object");
 507
 508                if (type != OBJ_TAG) {
 509                        ret = report(options, &tag->object,
 510                                FSCK_MSG_TAG_OBJECT_NOT_TAG,
 511                                "expected tag got %s",
 512                            typename(type));
 513                        goto done;
 514                }
 515        }
 516
 517        if (require_end_of_header(buffer, size, &tag->object, options))
 518                goto done;
 519
 520        if (!skip_prefix(buffer, "object ", &buffer)) {
 521                ret = report(options, &tag->object, FSCK_MSG_MISSING_OBJECT, "invalid format - expected 'object' line");
 522                goto done;
 523        }
 524        if (get_sha1_hex(buffer, sha1) || buffer[40] != '\n') {
 525                ret = report(options, &tag->object, FSCK_MSG_BAD_OBJECT_SHA1, "invalid 'object' line format - bad sha1");
 526                goto done;
 527        }
 528        buffer += 41;
 529
 530        if (!skip_prefix(buffer, "type ", &buffer)) {
 531                ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE_ENTRY, "invalid format - expected 'type' line");
 532                goto done;
 533        }
 534        eol = strchr(buffer, '\n');
 535        if (!eol) {
 536                ret = report(options, &tag->object, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line");
 537                goto done;
 538        }
 539        if (type_from_string_gently(buffer, eol - buffer, 1) < 0)
 540                ret = report(options, &tag->object, FSCK_MSG_BAD_TYPE, "invalid 'type' value");
 541        if (ret)
 542                goto done;
 543        buffer = eol + 1;
 544
 545        if (!skip_prefix(buffer, "tag ", &buffer)) {
 546                ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG_ENTRY, "invalid format - expected 'tag' line");
 547                goto done;
 548        }
 549        eol = strchr(buffer, '\n');
 550        if (!eol) {
 551                ret = report(options, &tag->object, FSCK_MSG_MISSING_TAG, "invalid format - unexpected end after 'type' line");
 552                goto done;
 553        }
 554        strbuf_addf(&sb, "refs/tags/%.*s", (int)(eol - buffer), buffer);
 555        if (check_refname_format(sb.buf, 0))
 556                report(options, &tag->object, FSCK_MSG_BAD_TAG_NAME,
 557                           "invalid 'tag' name: %.*s",
 558                           (int)(eol - buffer), buffer);
 559        buffer = eol + 1;
 560
 561        if (!skip_prefix(buffer, "tagger ", &buffer))
 562                /* early tags do not contain 'tagger' lines; warn only */
 563                report(options, &tag->object, FSCK_MSG_MISSING_TAGGER_ENTRY, "invalid format - expected 'tagger' line");
 564        else
 565                ret = fsck_ident(&buffer, &tag->object, options);
 566
 567done:
 568        strbuf_release(&sb);
 569        free(to_free);
 570        return ret;
 571}
 572
 573static int fsck_tag(struct tag *tag, const char *data,
 574        unsigned long size, struct fsck_options *options)
 575{
 576        struct object *tagged = tag->tagged;
 577
 578        if (!tagged)
 579                return report(options, &tag->object, FSCK_MSG_BAD_TAG_OBJECT, "could not load tagged object");
 580
 581        return fsck_tag_buffer(tag, data, size, options);
 582}
 583
 584int fsck_object(struct object *obj, void *data, unsigned long size,
 585        struct fsck_options *options)
 586{
 587        if (!obj)
 588                return report(options, obj, FSCK_MSG_BAD_OBJECT_SHA1, "no valid object to fsck");
 589
 590        if (obj->type == OBJ_BLOB)
 591                return 0;
 592        if (obj->type == OBJ_TREE)
 593                return fsck_tree((struct tree *) obj, options);
 594        if (obj->type == OBJ_COMMIT)
 595                return fsck_commit((struct commit *) obj, (const char *) data,
 596                        size, options);
 597        if (obj->type == OBJ_TAG)
 598                return fsck_tag((struct tag *) obj, (const char *) data,
 599                        size, options);
 600
 601        return report(options, obj, FSCK_MSG_UNKNOWN_TYPE, "unknown type '%d' (internal fsck error)",
 602                          obj->type);
 603}
 604
 605int fsck_error_function(struct object *obj, int msg_type, const char *message)
 606{
 607        error("object %s: %s", sha1_to_hex(obj->sha1), message);
 608        return 1;
 609}