git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fix segv with corrupt tag object

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 30, 2019, 16:29 UTC
Message-ID
<xmqqh85yzkfk.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<c6601cca-7de0-ba82-2e18-916a2e9048d3@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 40 quoted lines
> Subject: [PATCH] tree: simplify parse_tree_indirect()
>
> Reduce code duplication by turning parse_tree_indirect() into a wrapper
> of repo_peel_to_type().  This avoids a segfault when handling a broken
> tag where ->tagged is NULL.  The new version also checks the return
> value of parse_object() that was ignored by the old one.
>
> Initial-patch-by: Stefan Sperling <stsp@stsp.name>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  tree.c | 18 +++---------------
>  1 file changed, 3 insertions(+), 15 deletions(-)
>
> diff --git a/tree.c b/tree.c
> index 4720945e6a..1466bcc6a8 100644
> --- a/tree.c
> +++ b/tree.c
> @@ -244,19 +244,7 @@ void free_tree_buffer(struct tree *tree)
>
>  struct tree *parse_tree_indirect(const struct object_id *oid)
>  {
> -	struct object *obj = parse_object(the_repository, oid);
> -	do {
> -		if (!obj)
> -			return NULL;
> -		if (obj->type == OBJ_TREE)
> -			return (struct tree *) obj;
> -		else if (obj->type == OBJ_COMMIT)
> -			obj = &(get_commit_tree(((struct commit *)obj))->object);
> -		else if (obj->type == OBJ_TAG)
> -			obj = ((struct tag *) obj)->tagged;
> -		else
> -			return NULL;
> -		if (!obj->parsed)
> -			parse_object(the_repository, &obj->oid);
> -	} while (1);
> +	struct repository *r = the_repository;
> +	struct object *obj = parse_object(r, oid);
> +	return (struct tree *)repo_peel_to_type(r, NULL, 0, obj, OBJ_TREE);
>  }

Looks quite sensible to me; it is too simple that it makes me worried that I might be missing something huge.

Previous: René Scharfe
Message 8 of 8 in “fix segv with corrupt tag object”
  1. fix segv with corrupt tag objectStefan Sperling, Aug 24, 2019
  2. René ScharfeAug 25, 2019
  3. Stefan SperlingAug 26, 2019
  4. Junio C HamanoAug 26, 2019
  5. Stefan SperlingAug 26, 2019
  6. Jeff KingAug 26, 2019
  7. René ScharfeAug 29, 2019
  8. Junio C HamanoAug 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.