]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'maint-2.33' into maint-2.34
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Dec 2022 12:15:22 +0000 (21:15 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Dec 2022 12:15:22 +0000 (21:15 +0900)
1  2 
attr.c
git-compat-util.h
pretty.c
t/t0003-attributes.sh
t/t1450-fsck.sh
t/test-lib.sh

diff --cc attr.c
index 79adaa50ea1e099fa7f8bee28efa6f7f7d92223b,7f4f11a74c35306e57f7704c5ccdac932dbf0b0a..a658e35a58efb6c987d25c6c1277ef42c95c98ef
--- 1/attr.c
--- 2/attr.c
+++ b/attr.c
@@@ -745,23 -761,13 +762,27 @@@ static struct attr_stack *read_attr_fro
        if (!istate)
                return NULL;
  
-       buf = read_blob_data_from_index(istate, path, NULL);
 +      /*
 +       * The .gitattributes file only applies to files within its
 +       * parent directory. In the case of cone-mode sparse-checkout,
 +       * the .gitattributes file is sparse if and only if all paths
 +       * within that directory are also sparse. Thus, don't load the
 +       * .gitattributes file since it will not matter.
 +       *
 +       * In the case of a sparse index, it is critical that we don't go
 +       * looking for a .gitattributes file, as doing so would cause the
 +       * index to expand.
 +       */
 +      if (!path_in_cone_mode_sparse_checkout(path, istate))
 +              return NULL;
 +
+       buf = read_blob_data_from_index(istate, path, &size);
        if (!buf)
                return NULL;
+       if (size >= ATTR_MAX_FILE_SIZE) {
+               warning(_("ignoring overly large gitattributes blob '%s'"), path);
+               return NULL;
+       }
  
        CALLOC_ARRAY(res, 1);
        for (sp = buf; *sp; ) {
Simple merge
diff --cc pretty.c
Simple merge
Simple merge
diff --cc t/t1450-fsck.sh
index 6337236fd8226b1902f11ebf54ff9e6d02f537e2,9e0afe1fbf85f3438b956bb75a1e932f335606ed..36858878a0b1c6fcedf1b8aa7020b7bca3ec958c
@@@ -911,21 -865,28 +911,45 @@@ test_expect_success 'detect corrupt ind
        test_i18ngrep "bad index file" errors
  '
  
 +test_expect_success 'fsck error and recovery on invalid object type' '
 +      git init --bare garbage-type &&
 +      (
 +              cd garbage-type &&
 +
 +              garbage_blob=$(git hash-object --stdin -w -t garbage --literally </dev/null) &&
 +
 +              cat >err.expect <<-\EOF &&
 +              fatal: invalid object type
 +              EOF
 +              test_must_fail git fsck >out 2>err &&
 +              grep -e "^error" -e "^fatal" err >errors &&
 +              test_line_count = 1 errors &&
 +              grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err
 +      )
 +'
 +
+ test_expect_success 'fsck error on gitattributes with excessive line lengths' '
+       blob=$(printf "pattern %02048d" 1 | git hash-object -w --stdin) &&
+       test_when_finished "remove_object $blob" &&
+       tree=$(printf "100644 blob %s\t%s\n" $blob .gitattributes | git mktree) &&
+       test_when_finished "remove_object $tree" &&
+       cat >expected <<-EOF &&
+       error in blob $blob: gitattributesLineLength: .gitattributes has too long lines to parse
+       EOF
+       test_must_fail git fsck --no-dangling >actual 2>&1 &&
+       test_cmp expected actual
+ '
+ test_expect_success 'fsck error on gitattributes with excessive size' '
+       blob=$(test-tool genzeros $((100 * 1024 * 1024 + 1)) | git hash-object -w --stdin) &&
+       test_when_finished "remove_object $blob" &&
+       tree=$(printf "100644 blob %s\t%s\n" $blob .gitattributes | git mktree) &&
+       test_when_finished "remove_object $tree" &&
+       cat >expected <<-EOF &&
+       error in blob $blob: gitattributesLarge: .gitattributes too large to parse
+       EOF
+       test_must_fail git fsck --no-dangling >actual 2>&1 &&
+       test_cmp expected actual
+ '
  test_done
diff --cc t/test-lib.sh
Simple merge