Re: [PATCH v3 14/17] fsck: don't hard die on invalid object types
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- May 27, 2021, 18:18 UTC
- Message-ID
- <20210527181848.2679147-1-jonathantanmy@google.com>
- In-Reply-To
- <patch-14.17-260e9888a3-20210520T111610Z-avarab@gmail.com>
Show 36 quoted lines
> diff --git a/object-file.c b/object-file.c
> index 0de699de98..0e8a024eb3 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -2522,7 +2522,8 @@ int read_loose_object(const char *path,
> const struct object_id *expected_oid,
> enum object_type *type,
> unsigned long *size,
> - void **contents)
> + void **contents,
> + unsigned int oi_flags)
> {
> int ret = -1;
> void *map = NULL;
> @@ -2530,6 +2531,7 @@ int read_loose_object(const char *path,
> git_zstream stream;
> char hdr[MAX_HEADER_LEN];
> struct object_info oi = OBJECT_INFO_INIT;
> + int allow_unknown = oi_flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
> oi.typep = type;
> oi.sizep = size;
>
> @@ -2552,8 +2554,11 @@ int read_loose_object(const char *path,
> git_inflate_end(&stream);
> goto out;
> }
> - if (*type < 0)
> - die(_("invalid object type"));
> + if (!allow_unknown && *type < 0) {
> + error(_("header for %s declares an unknown type"), path);
> + git_inflate_end(&stream);
> + goto out;
> + }
>
> if (*type == OBJ_BLOB && *size > big_file_threshold) {
> if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)So instead of dying, we print an error and behave as if the object was invalid for some other reason. Makes sense.