]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'maint-2.34' into maint-2.35
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Dec 2022 12:17:10 +0000 (21:17 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Dec 2022 12:17:10 +0000 (21:17 +0900)
1  2 
git-compat-util.h
pretty.c
t/t1450-fsck.sh
t/t4205-log-pretty-formats.sh

index 65f82607cc6aa4fdba1134db18167790439bf33e,ed0892b3c8f19d05de3b0671559022f40d649b2e..1c651c880e43ada6d7ef04238c1aa01ed73379cb
@@@ -964,23 -932,14 +964,31 @@@ static inline size_t st_sub(size_t a, s
        return a - b;
  }
  
 +static inline size_t st_left_shift(size_t a, unsigned shift)
 +{
 +      if (unsigned_left_shift_overflows(a, shift))
 +              die("size_t overflow: %"PRIuMAX" << %u",
 +                  (uintmax_t)a, shift);
 +      return a << shift;
 +}
 +
 +static inline unsigned long cast_size_t_to_ulong(size_t a)
 +{
 +      if (a != (unsigned long)a)
 +              die("object too large to read on this platform: %"
 +                  PRIuMAX" is cut off to %lu",
 +                  (uintmax_t)a, (unsigned long)a);
 +      return (unsigned long)a;
 +}
 +
+ static inline int cast_size_t_to_int(size_t a)
+ {
+       if (a > INT_MAX)
+               die("number too large to represent as int on this platform: %"PRIuMAX,
+                   (uintmax_t)a);
+       return (int)a;
+ }
  #ifdef HAVE_ALLOCA_H
  # include <alloca.h>
  # define xalloca(size)      (alloca(size))
diff --cc pretty.c
Simple merge
diff --cc t/t1450-fsck.sh
Simple merge
index e448ef2928a8261e7c991ee6eb0e96bf299d84ee,c66db6391f3a0af64e17208e42f8936f7c9d982d..fedb7ca7493f650ce9def7179cf63fa11ef90d70
@@@ -1002,20 -1002,80 +1002,96 @@@ test_expect_success '%(describe:exclude
        test_cmp expect actual
  '
  
 +test_expect_success '%(describe:tags) vs git describe --tags' '
 +      test_when_finished "git tag -d tagname" &&
 +      git tag tagname &&
 +      git describe --tags >expect &&
 +      git log -1 --format="%(describe:tags)" >actual &&
 +      test_cmp expect actual
 +'
 +
 +test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' '
 +      test_when_finished "git tag -d tagname" &&
 +      git tag -a -m tagged tagname &&
 +      git describe --abbrev=15 >expect &&
 +      git log -1 --format="%(describe:abbrev=15)" >actual &&
 +      test_cmp expect actual
 +'
 +
+ test_expect_success 'log --pretty with space stealing' '
+       printf mm0 >expect &&
+       git log -1 --pretty="format:mm%>>|(1)%x30" >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'log --pretty with invalid padding format' '
+       printf "%s%%<(20" "$(git rev-parse HEAD)" >expect &&
+       git log -1 --pretty="format:%H%<(20" >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'log --pretty with magical wrapping directives' '
+       commit_id=$(git commit-tree HEAD^{tree} -m "describe me") &&
+       git tag describe-me $commit_id &&
+       printf "\n(tag:\ndescribe-me)%%+w(2)" >expect &&
+       git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' '
+       printf "%%w(2147483649,1,1)0" >expect &&
+       git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual &&
+       test_cmp expect actual &&
+       printf "%%w(1,2147483649,1)0" >expect &&
+       git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual &&
+       test_cmp expect actual &&
+       printf "%%w(1,1,2147483649)0" >expect &&
+       git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' '
+       printf "%%<(2147483649)0" >expect &&
+       git log -1 --pretty="format:%<(2147483649)%x30" >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'log --pretty with padding and preceding control chars' '
+       printf "\20\20   0" >expect &&
+       git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success 'log --pretty truncation with control chars' '
+       test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars &&
+       printf "\20\20\20\20x.." >expect &&
+       git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual &&
+       test_cmp expect actual
+ '
+ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' '
+       # We only assert that this command does not crash. This needs to be
+       # executed with the address sanitizer to demonstrate failure.
+       git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null
+ '
+ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' '
+       test-tool genzeros 2147483649 | tr "\000" "1" >expect &&
+       huge_commit=$(git commit-tree -F expect HEAD^{tree})
+ '
+ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' '
+       git log -1 --format="%B%<(1)%x30" $huge_commit >actual &&
+       echo 0 >>expect &&
+       test_cmp expect actual
+ '
+ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' '
+       test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error &&
+       cat >expect <<-EOF &&
+       fatal: number too large to represent as int on this platform: 2147483649
+       EOF
+       test_cmp expect error
+ '
  test_done