log: handle integer overflow in timestamps
[git.git] / t / t4212-log-corrupt.sh
blob80542d624be2881f1aa9242402b494dff8bd5353
1 #!/bin/sh
3 test_description='git log with invalid commit headers'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit foo &&
10 git cat-file commit HEAD |
11 sed "/^author /s/>/>-<>/" >broken_email.commit &&
12 git hash-object -w -t commit broken_email.commit >broken_email.hash &&
13 git update-ref refs/heads/broken_email $(cat broken_email.hash)
16 test_expect_success 'git log with broken author email' '
18 echo commit $(cat broken_email.hash)
19 echo "Author: A U Thor <author@example.com>"
20 echo "Date: Thu Jan 1 00:00:00 1970 +0000"
21 echo
22 echo " foo"
23 } >expect.out &&
24 : >expect.err &&
26 git log broken_email >actual.out 2>actual.err &&
28 test_cmp expect.out actual.out &&
29 test_cmp expect.err actual.err
32 test_expect_success 'git log --format with broken author email' '
33 echo "A U Thor+author@example.com+" >expect.out &&
34 : >expect.err &&
36 git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err &&
38 test_cmp expect.out actual.out &&
39 test_cmp expect.err actual.err
42 munge_author_date () {
43 git cat-file commit "$1" >commit.orig &&
44 sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge &&
45 git hash-object -w -t commit commit.munge
48 test_expect_success 'unparsable dates produce sentinel value' '
49 commit=$(munge_author_date HEAD totally_bogus) &&
50 echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect &&
51 git log -1 $commit >actual.full &&
52 grep Date <actual.full >actual &&
53 test_cmp expect actual
56 test_expect_success 'unparsable dates produce sentinel value (%ad)' '
57 commit=$(munge_author_date HEAD totally_bogus) &&
58 echo >expect &&
59 git log -1 --format=%ad $commit >actual
60 test_cmp expect actual
63 # date is 2^64 + 1
64 test_expect_success 'date parser recognizes integer overflow' '
65 commit=$(munge_author_date HEAD 18446744073709551617) &&
66 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
67 git log -1 --format=%ad $commit >actual &&
68 test_cmp expect actual
71 # date is 2^64 - 2
72 test_expect_success 'date parser recognizes time_t overflow' '
73 commit=$(munge_author_date HEAD 18446744073709551614) &&
74 echo "Thu Jan 1 00:00:00 1970 +0000" >expect &&
75 git log -1 --format=%ad $commit >actual &&
76 test_cmp expect actual
79 test_done