]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ab/fsck-unexpected-type'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Oct 2021 23:06:56 +0000 (16:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Oct 2021 23:06:56 +0000 (16:06 -0700)
"git fsck" has been taught to report mismatch between expected and
actual types of an object better.

* ab/fsck-unexpected-type:
  fsck: report invalid object type-path combinations
  fsck: don't hard die on invalid object types
  object-file.c: stop dying in parse_loose_header()
  object-file.c: return ULHR_TOO_LONG on "header too long"
  object-file.c: use "enum" return type for unpack_loose_header()
  object-file.c: simplify unpack_loose_short_header()
  object-file.c: make parse_loose_header_extended() public
  object-file.c: return -1, not "status" from unpack_loose_header()
  object-file.c: don't set "typep" when returning non-zero
  cat-file tests: test for current --allow-unknown-type behavior
  cat-file tests: add corrupt loose object test
  cat-file tests: test for missing/bogus object with -t, -s and -p
  cat-file tests: move bogus_* variable declarations earlier
  fsck tests: test for garbage appended to a loose object
  fsck tests: test current hash/type mismatch behavior
  fsck tests: refactor one test to use a sub-repo
  fsck tests: add test for fsck-ing an unknown type

1  2 
builtin/fast-export.c
builtin/fsck.c
builtin/index-pack.c
cache.h
object-file.c
object-store.h
object.c
pack-check.c
t/t1006-cat-file.sh

Simple merge
diff --cc builtin/fsck.c
Simple merge
Simple merge
diff --cc cache.h
Simple merge
diff --cc object-file.c
Simple merge
diff --cc object-store.h
Simple merge
diff --cc object.c
Simple merge
diff --cc pack-check.c
Simple merge
index 4a753705ec2c392f1b15f1015557b405e38c0648,fe302f2818dbeda2d1cadd6850b5e8f9fa21c325..658628375c85b17e44aa501c7624daddff4053f6
@@@ -332,18 -475,9 +475,13 @@@ test_expect_success "Size of broken obj
        test_cmp expect actual
  '
  
-       rm .git/objects/$(test_oid_to_path $bogus_sha1)
 +test_expect_success 'clean up broken object' '
- bogus_type="abcdefghijklmnopqrstuvwxyz1234679"
- bogus_content="bogus"
- bogus_size=$(strlen "$bogus_content")
- bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
++      rm .git/objects/$(test_oid_to_path $bogus_short_sha1)
 +'
 +
  test_expect_success "Type of broken object is correct when type is large" '
-       echo $bogus_type >expect &&
-       git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
+       echo $bogus_long_type >expect &&
+       git cat-file -t --allow-unknown-type $bogus_long_sha1 >actual &&
        test_cmp expect actual
  '
  
@@@ -353,8 -487,56 +491,60 @@@ test_expect_success "Size of large brok
        test_cmp expect actual
  '
  
-       rm .git/objects/$(test_oid_to_path $bogus_sha1)
 +test_expect_success 'clean up broken object' '
++      rm .git/objects/$(test_oid_to_path $bogus_long_sha1)
++'
++
+ test_expect_success 'cat-file -t and -s on corrupt loose object' '
+       git init --bare corrupt-loose.git &&
+       (
+               cd corrupt-loose.git &&
+               # Setup and create the empty blob and its path
+               empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) &&
+               git hash-object -w --stdin </dev/null &&
+               # Create another blob and its path
+               echo other >other.blob &&
+               other_blob=$(git hash-object -w --stdin <other.blob) &&
+               other_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$other_blob")) &&
+               # Before the swap the size is 0
+               cat >out.expect <<-EOF &&
+               0
+               EOF
+               git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
+               test_must_be_empty err.actual &&
+               test_cmp out.expect out.actual &&
+               # Swap the two to corrupt the repository
+               mv -f "$other_path" "$empty_path" &&
+               test_must_fail git fsck 2>err.fsck &&
+               grep "hash-path mismatch" err.fsck &&
+               # confirm that cat-file is reading the new swapped-in
+               # blob...
+               cat >out.expect <<-EOF &&
+               blob
+               EOF
+               git cat-file -t "$EMPTY_BLOB" >out.actual 2>err.actual &&
+               test_must_be_empty err.actual &&
+               test_cmp out.expect out.actual &&
+               # ... since it has a different size now.
+               cat >out.expect <<-EOF &&
+               6
+               EOF
+               git cat-file -s "$EMPTY_BLOB" >out.actual 2>err.actual &&
+               test_must_be_empty err.actual &&
+               test_cmp out.expect out.actual &&
+               # So far "cat-file" has been happy to spew the found
+               # content out as-is. Try to make it zlib-invalid.
+               mv -f other.blob "$empty_path" &&
+               test_must_fail git fsck 2>err.fsck &&
+               grep "^error: inflate: data stream error (" err.fsck
+       )
  '
  
  # Tests for git cat-file --follow-symlinks