Subject: Re: [PATCH v3 4/4] last-modified: verify revision argument is a commit-ish

From: Junio C Hamano <[email-masked]>
Date: Fri, 16 Jan 2026 10:24:44 -0800

Toon Claes <[email-masked]> writes:

> Passing a tree OID to git-last-modified(1) would trigger BUG behavior.
>
>     git last-modified HEAD^{tree}
>     BUG: builtin/last-modified.c:456: paths remaining beyond boundary in last-modified
>
> Fix this error by verifying the parsed revision is a commit-ish.
>
> Reported-by: Gusted <[email-masked]>
> Signed-off-by: Toon Claes <[email-masked]>
> ---
>  builtin/last-modified.c  |  5 +++++
>  t/t8020-last-modified.sh | 13 +++++++++++++
>  2 files changed, 18 insertions(+)
>
> diff --git a/builtin/last-modified.c b/builtin/last-modified.c
> index 0df85be318..5366cedd0f 100644
> --- a/builtin/last-modified.c
> +++ b/builtin/last-modified.c
> @@ -150,6 +150,11 @@ static int populate_paths_from_revs(struct last_modified *lm)
>  			goto out;
>  		}
>  
> +		if (!repo_peel_to_type(lm->rev.repo, obj->path, 0, obj->item, OBJ_COMMIT)) {
> +			ret = error(_("revision argument is not a commit-ish"));
> +			goto out;
> +		}

This will do, at least for now, but I tend to prefer to say what the
user gave us when we expected a commit, e.g., "commit expected, got
a tree".