git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Taylor Blau" <me@ttaylorr.com>,
	"Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Jonathan Tan" <jonathantanmy@google.com>,
	"Kousik Sanagavarapu" <five231003@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 0/3] tag: don't misreport type of tagged objects in errors
Date: Fri, 30 Dec 2022 02:52:13 +0100	[thread overview]
Message-ID: <cover-v2-0.3-00000000000-20221230T011725Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.4-00000000000-20221118T113442Z-avarab@gmail.com>

This series fixes a very long-standing issue where we'll get confused
when we parse a tag whose "type" lies about the type of the target
object.

The v1 was on top of jk/parse-object-type-mismatch, which has since
landed on "master". As I noted in [1] this covers remaining
misreporting cases which weren't addressed in that series.

Currently we'll parse tags and note what the "type" claims to be. Say
a pointer to a "blob" object that claims to be a "commit" in the
envelope.

Then when we we'd try to parse that supposed "commit' for real we'd
emit a message like:

	error: object <oid> is a blob, not a commit

Which is reversed, i.e. we'd remember the first "blob" we saw, and
then get confused about seeing a "commit" when we did the actual
parsing.

This is now fixed in almost all cases by having the one caller of
parse_tag() which actually knows the type tell it "yes, I'm sure this
is a commit".

We'll then be able to see that we have a non-parsed object as
scaffolding, but that it's really a commit, and emit the correct:

	error: object <oid> is a commit not a blob

Which goes along with other errors where the tag object itself yells
about being unhappy with the object reference.

I submitted a version of these patches back in early 2021[2], this is
significantly slimmed down since then.

At the time Jeff King noted[3] that this approach inherently can't cover
all possible scenarios. I.e. sometimes our parsing of the envelope
isn't followed up by the "real" parse.

Even in those cases we can "get it right as 3/3 here demonstrates.

But there are going to be cases left where we get it wrong, but
they're all cases where we get it wrong now. It's probably not worth
fixing the long tail of those issues, but now we'll emit a sensible
error on the common case of "log" etc.

Changes since v1:

* The v1 of this included a fix for the t.tag memory leak, which has
  now been ejected. I'm fixing that in another series[4]

  As a result we need to mark the new tests with !SANITIZE_LEAK, once
  some version of [4] lands we can un-mark these, so we'll test them
  under SANITIZE=leak.

* In the previous 1st patch I marked a "setup" test as
  "test_expect_failure", which will pass at that point, let's make it
  "test_expect_success" from the outset.

CI & branch at [5]. The "win build" CI failure is unrelated, it also
happens when I re-push master, root cause unknown, but unrelated to
this topic.

1. https://lore.kernel.org/git/221118.86cz9lgjxu.gmgdl@evledraar.gmail.com/
2. https://lore.kernel.org/git/cover-00.11-00000000000-20210328T021238Z-avarab@gmail.com/
3. https://lore.kernel.org/git/YGTGgFI19fS7Uv6I@coredump.intra.peff.net/
4. https://lore.kernel.org/git/cover-00.20-00000000000-20221228T175512Z-avarab@gmail.com/
5. https://github.com/avar/git/tree/avar/correct-object-as-type-minimal-2


Ævar Arnfjörð Bjarmason (3):
  object tests: add test for unexpected objects in tags
  tag: don't misreport type of tagged objects in errors
  tag: don't emit potentially incorrect "object is a X, not a Y"

 blob.c                                 |  11 +-
 blob.h                                 |   3 +
 commit.c                               |  11 +-
 commit.h                               |   2 +
 object.c                               |  20 +++-
 object.h                               |   2 +
 t/t6102-rev-list-unexpected-objects.sh | 146 +++++++++++++++++++++++++
 tag.c                                  |  22 +++-
 tag.h                                  |   2 +
 tree.c                                 |  11 +-
 tree.h                                 |   2 +
 11 files changed, 218 insertions(+), 14 deletions(-)

Range-diff against v1:
1:  2be8477cd78 < -:  ----------- object-file.c: free the "t.tag" in check_tag()
2:  1b5544ec868 ! 1:  0abf873f1e3 object tests: add test for unexpected objects in tags
    @@ Commit message
         report, and asserting that those are correct (currently, it's far from
         correct).
     
    +    As these tests happen to run into a memory leak skip them under
    +    SANITIZE=leak, as the test file was previously marked leak-free in
    +    [3]. There is a concurrent fix for the leak in question[4].
    +
         1. https://lore.kernel.org/git/YGTGgFI19fS7Uv6I@coredump.intra.peff.net/
    +    2. https://lore.kernel.org/git/patch-18.20-aa4df0e1b5c-20221228T175512Z-avarab@gmail.com/
    +    3. dd9cede9136 (leak tests: mark some rev-list tests as passing with
    +       SANITIZE=leak, 2021-10-31)
    +    4. https://lore.kernel.org/git/patch-18.20-aa4df0e1b5c-20221228T175512Z-avarab@gmail.com/
     
         Helped-by: Jeff King <peff@peff.net>
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
      	test_i18ngrep "not a blob" output
      '
      
    -+test_expect_success 'setup unexpected non-tag tag' '
    ++test_expect_success !SANITIZE_LEAK 'setup unexpected non-tag tag' '
     +	test_when_finished "git tag -d tag-commit tag-tag" &&
     +
     +	git tag -a -m"my tagged commit" tag-commit $commit &&
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +	git update-ref refs/tags/commit_tag_blob $commit_tag_blob
     +'
     +
    -+test_expect_failure 'traverse unexpected incorrectly typed tag (to commit & tag)' '
    ++test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to commit & tag)' '
     +	test_must_fail git rev-list --objects $tag_tag_commit 2>err &&
     +	cat >expect <<-EOF &&
     +	error: object $commit is a commit, not a tag
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +	test_cmp expect err
     +'
     +
    -+test_expect_failure 'traverse unexpected incorrectly typed tag (to tree)' '
    ++test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to tree)' '
     +	test_must_fail git rev-list --objects $tag_tag_tree 2>err &&
     +	cat >expect <<-EOF &&
     +	error: object $tree is a tree, not a tag
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +	test_cmp expect err
     +'
     +
    -+test_expect_failure 'traverse unexpected incorrectly typed tag (to blob)' '
    ++test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to blob)' '
     +	test_must_fail git rev-list --objects $tag_tag_blob 2>err &&
     +	cat >expect <<-EOF &&
     +	error: object $blob is a blob, not a tag
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +	test_cmp expect err
     +'
     +
    -+test_expect_failure 'traverse unexpected non-tag tag (tree seen to blob)' '
    ++test_expect_failure !SANITIZE_LEAK 'traverse unexpected non-tag tag (tree seen to blob)' '
     +	test_must_fail git rev-list --objects $tree $commit_tag_blob 2>err &&
     +	cat >expect <<-EOF &&
     +	error: object $blob is a blob, not a commit
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +'
     +
     +
    -+test_expect_failure 'traverse unexpected objects with for-each-ref' '
    ++test_expect_failure !SANITIZE_LEAK 'traverse unexpected objects with for-each-ref' '
     +	cat >expect <<-EOF &&
     +	error: bad tag pointer to $tree in $tag_tag_tree
     +	fatal: parse_object_buffer failed on $tag_tag_tree for refs/tags/tag_tag_tree
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +'
     +
     +>fsck-object-isa
    -+test_expect_failure 'setup: unexpected objects with fsck' '
    ++test_expect_success 'setup: unexpected objects with fsck' '
     +	test_must_fail git fsck 2>err &&
     +	sed -n -e "/^error: object .* is a .*, not a .*$/ {
     +		s/^error: object \([0-9a-f]*\) is a \([a-z]*\), not a [a-z]*$/\\1 \\2/;
    @@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected
     +	'
     +done <fsck-object-isa
     +
    -+test_expect_success 'traverse unexpected non-tag tag (blob seen to blob)' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected non-tag tag (blob seen to blob)' '
     +	test_must_fail git rev-list --objects $blob $commit_tag_blob 2>err &&
     +	cat >expected <<-EOF &&
     +	error: object $blob is a blob, not a commit
3:  468af961dc4 ! 2:  96398731841 tag: don't misreport type of tagged objects in errors
    @@ blob.c
     +	return lookup_blob_type(r, oid, OBJ_NONE);
      }
      
    - int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
    + void parse_blob_buffer(struct blob *item)
     
      ## blob.h ##
     @@ blob.h: struct blob {
    @@ blob.h: struct blob {
     +			      const struct object_id *oid,
     +			      enum object_type type);
      
    - int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size);
    - 
    + /**
    +  * Blobs do not contain references to other objects and do not have
     
      ## commit.c ##
     @@ commit.c: struct commit *lookup_commit_object(struct repository *r,
    @@ object.c: struct object *parse_object_buffer(struct repository *r, const struct
     -		struct blob *blob = lookup_blob(r, oid);
     +		struct blob *blob = lookup_blob_type(r, oid, type);
      		if (blob) {
    - 			if (parse_blob_buffer(blob, buffer, size))
    - 				return NULL;
    + 			parse_blob_buffer(blob);
      			obj = &blob->object;
      		}
      	} else if (type == OBJ_TREE) {
    @@ object.h: struct object *lookup_object(struct repository *r, const struct object
       * Returns the object, having parsed it to find out what it is.
     
      ## t/t6102-rev-list-unexpected-objects.sh ##
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'setup unexpected non-tag tag' '
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success !SANITIZE_LEAK 'setup unexpected non-tag tag' '
      	git update-ref refs/tags/commit_tag_blob $commit_tag_blob
      '
      
    --test_expect_failure 'traverse unexpected incorrectly typed tag (to commit & tag)' '
    -+test_expect_success 'traverse unexpected incorrectly typed tag (to commit & tag)' '
    +-test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to commit & tag)' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to commit & tag)' '
      	test_must_fail git rev-list --objects $tag_tag_commit 2>err &&
      	cat >expect <<-EOF &&
      	error: object $commit is a commit, not a tag
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure 'traverse unexpected incorrectly typed tag (to commit & tag)
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (t
      	test_cmp expect err
      '
      
    --test_expect_failure 'traverse unexpected incorrectly typed tag (to tree)' '
    -+test_expect_success 'traverse unexpected incorrectly typed tag (to tree)' '
    +-test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to tree)' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to tree)' '
      	test_must_fail git rev-list --objects $tag_tag_tree 2>err &&
      	cat >expect <<-EOF &&
      	error: object $tree is a tree, not a tag
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure 'traverse unexpected incorrectly typed tag (to tree)' '
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (t
      	test_cmp expect err
      '
      
    --test_expect_failure 'traverse unexpected incorrectly typed tag (to blob)' '
    -+test_expect_success 'traverse unexpected incorrectly typed tag (to blob)' '
    +-test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to blob)' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (to blob)' '
      	test_must_fail git rev-list --objects $tag_tag_blob 2>err &&
      	cat >expect <<-EOF &&
      	error: object $blob is a blob, not a tag
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure 'traverse unexpected incorrectly typed tag (to blob)' '
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure !SANITIZE_LEAK 'traverse unexpected incorrectly typed tag (t
      	test_cmp expect err
      '
      
    --test_expect_failure 'traverse unexpected non-tag tag (tree seen to blob)' '
    -+test_expect_success 'traverse unexpected non-tag tag (tree seen to blob)' '
    +-test_expect_failure !SANITIZE_LEAK 'traverse unexpected non-tag tag (tree seen to blob)' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected non-tag tag (tree seen to blob)' '
      	test_must_fail git rev-list --objects $tree $commit_tag_blob 2>err &&
      	cat >expect <<-EOF &&
      	error: object $blob is a blob, not a commit
4:  1a9dcb9e05d ! 3:  2493988c41c tag: don't emit potentially incorrect "object is a X, not a Y"
    @@ Commit message
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## t/t6102-rev-list-unexpected-objects.sh ##
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'traverse unexpected non-tag tag (tree seen to blob)' '
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success !SANITIZE_LEAK 'traverse unexpected non-tag tag (tree seen t
      '
      
      
    --test_expect_failure 'traverse unexpected objects with for-each-ref' '
    -+test_expect_success 'traverse unexpected objects with for-each-ref' '
    +-test_expect_failure !SANITIZE_LEAK 'traverse unexpected objects with for-each-ref' '
    ++test_expect_success !SANITIZE_LEAK 'traverse unexpected objects with for-each-ref' '
      	cat >expect <<-EOF &&
      	error: bad tag pointer to $tree in $tag_tag_tree
      	fatal: parse_object_buffer failed on $tag_tag_tree for refs/tags/tag_tag_tree
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure 'traverse unexpected objects with for-each-ref' '
    - '
    - 
    - >fsck-object-isa
    --test_expect_failure 'setup: unexpected objects with fsck' '
    -+test_expect_success 'setup: unexpected objects with fsck' '
    - 	test_must_fail git fsck 2>err &&
    - 	sed -n -e "/^error: object .* is a .*, not a .*$/ {
    - 		s/^error: object \([0-9a-f]*\) is a \([a-z]*\), not a [a-z]*$/\\1 \\2/;
    -@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_failure 'setup: unexpected objects with fsck' '
    +@@ t/t6102-rev-list-unexpected-objects.sh: test_expect_success 'setup: unexpected objects with fsck' '
      
      while read oid type
      do
-- 
2.39.0.1153.g589e4efe9dc


  parent reply	other threads:[~2022-12-30  1:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 16:39 [RFC][PATCH] object.c: use has_object() instead of repo_has_object_file() Kousik Sanagavarapu
2022-11-16 18:20 ` Jeff King
2022-11-16 21:14   ` Jonathan Tan
2022-11-17 22:37     ` [PATCH 0/2] fixing parse_object() check for type mismatch Jeff King
2022-11-17 22:37       ` [PATCH 1/2] parse_object(): drop extra "has" check before checking object type Jeff King
2022-11-17 22:41       ` [PATCH 2/2] parse_object(): check on-disk type of suspected blob Jeff King
2022-11-18  0:36         ` Ævar Arnfjörð Bjarmason
2022-11-21 19:21           ` Jeff King
2022-11-18 11:46       ` [PATCH 0/4] tag: don't misreport type of tagged objects in errors Ævar Arnfjörð Bjarmason
2022-11-18 11:46         ` [PATCH 1/4] object-file.c: free the "t.tag" in check_tag() Ævar Arnfjörð Bjarmason
2022-11-18 11:46         ` [PATCH 2/4] object tests: add test for unexpected objects in tags Ævar Arnfjörð Bjarmason
2022-11-18 11:46         ` [PATCH 3/4] tag: don't misreport type of tagged objects in errors Ævar Arnfjörð Bjarmason
2022-11-18 11:46         ` [PATCH 4/4] tag: don't emit potentially incorrect "object is a X, not a Y" Ævar Arnfjörð Bjarmason
2022-12-30  1:52         ` Ævar Arnfjörð Bjarmason [this message]
2022-12-30  1:52           ` [PATCH v2 1/3] object tests: add test for unexpected objects in tags Ævar Arnfjörð Bjarmason
2022-12-30  4:25             ` Junio C Hamano
2022-12-30  1:52           ` [PATCH v2 2/3] tag: don't misreport type of tagged objects in errors Ævar Arnfjörð Bjarmason
2022-12-30  6:07             ` Junio C Hamano
2022-12-30  1:52           ` [PATCH v2 3/3] tag: don't emit potentially incorrect "object is a X, not a Y" Ævar Arnfjörð Bjarmason
2022-11-18 19:05       ` [PATCH 0/2] fixing parse_object() check for type mismatch Taylor Blau
2022-11-21 19:26         ` Jeff King
2022-11-22  0:05           ` Ævar Arnfjörð Bjarmason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover-v2-0.3-00000000000-20221230T011725Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=five231003@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).