tests/test-parseindex.t
author pacien <pacien.trangirard@pacien.net>
Thu, 22 Sep 2022 16:09:53 +0200
changeset 49499 4f36738a869a
parent 49221 75d0775dce7f
child 51076 786b6225793a
permissions -rw-r--r--
tests: fix http-bad-server expected errors for python 3.10 (issue6643) The format of the error message changed with this version of Python. This also removes obsolete Python 3 checks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     1
revlog.parseindex must be able to parse the index file even if
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     2
an index entry is split between two 64k blocks.  The ideal test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     3
would be to create an index file with inline data where
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     4
64k < size < 64k + 64 (64k is the size of the read buffer, 64 is
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     5
the size of an index entry) and with an index entry starting right
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     6
before the 64k block boundary, and try to read it.
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     7
We approximate that by reducing the read buffer to 1 byte.
2290
6563438219e3 add test for revlog.parseindex
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     8
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
     9
  $ hg init a
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    10
  $ cd a
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    11
  $ echo abc > foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    12
  $ hg add foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    13
  $ hg commit -m 'add foo'
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    14
  $ echo >> foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    15
  $ hg commit -m 'change foo'
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    16
  $ hg log -r 0:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    17
  changeset:   0:7c31755bf9b5
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    18
  user:        test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    19
  date:        Thu Jan 01 00:00:00 1970 +0000
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    20
  summary:     add foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    21
  
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    22
  changeset:   1:26333235a41c
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    23
  tag:         tip
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    24
  user:        test
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    25
  date:        Thu Jan 01 00:00:00 1970 +0000
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    26
  summary:     change foo
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    27
  
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    28
  $ cat >> test.py << EOF
41353
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
    29
  > from mercurial import changelog, node, pycompat, vfs
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    30
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    31
  > class singlebyteread(object):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    32
  >     def __init__(self, real):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    33
  >         self.real = real
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    34
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    35
  >     def read(self, size=-1):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    36
  >         if size == 65536:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    37
  >             size = 1
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    38
  >         return self.real.read(size)
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    39
  > 
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    40
  >     def __getattr__(self, key):
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    41
  >         return getattr(self.real, key)
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    42
  > 
35966
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    43
  >     def __enter__(self):
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    44
  >         self.real.__enter__()
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    45
  >         return self
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    46
  > 
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    47
  >     def __exit__(self, *args, **kwargs):
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    48
  >         return self.real.__exit__(*args, **kwargs)
8140ce44dec4 parseindex: implement context manager method on the wrapper
Boris Feld <boris.feld@octobus.net>
parents: 35965
diff changeset
    49
  > 
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    50
  > def opener(*args):
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    51
  >     o = vfs.vfs(*args)
35965
c839bbee1e13 parseindex: also forward keyword argument in a debug wrapper
Boris Feld <boris.feld@octobus.net>
parents: 33262
diff changeset
    52
  >     def wrapper(*a, **kwargs):
c839bbee1e13 parseindex: also forward keyword argument in a debug wrapper
Boris Feld <boris.feld@octobus.net>
parents: 33262
diff changeset
    53
  >         f = o(*a, **kwargs)
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    54
  >         return singlebyteread(f)
43025
3518da504303 vfs: give all vfs an options attribute by default
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41353
diff changeset
    55
  >     wrapper.options = o.options
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    56
  >     return wrapper
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    57
  > 
41353
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
    58
  > cl = changelog.changelog(opener(b'.hg/store'))
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    59
  > print(len(cl), 'revisions:')
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    60
  > for r in cl:
41353
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
    61
  >     print(pycompat.sysstr(node.short(cl.node(r))))
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    62
  > EOF
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
    63
  $ "$PYTHON" test.py
12476
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    64
  2 revisions:
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    65
  7c31755bf9b5
4cce5194c307 tests: unify test-parseindex
Matt Mackall <mpm@selenic.com>
parents: 12156
diff changeset
    66
  26333235a41c
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13970
diff changeset
    67
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 13970
diff changeset
    68
  $ cd ..
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
    69
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    70
#if no-pure
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    71
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    72
Test SEGV caused by bad revision passed to reachableroots() (issue4775):
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    73
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    74
  $ cd a
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
    75
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
    76
  $ "$PYTHON" <<EOF
31250
6d44de27790c vfs: use 'vfs' module directly in 'test-parseindex'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    77
  > from mercurial import changelog, vfs
41353
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
    78
  > cl = changelog.changelog(vfs.vfs(b'.hg/store'))
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    79
  > print('good heads:')
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    80
  > for head in [0, len(cl) - 1, -1]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    81
  >     print('%s: %r' % (head, cl.reachableroots(0, [head], [0])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    82
  > print('bad heads:')
26018
c6115c30a376 reachableroots: verify type of each item of heads argument
Yuya Nishihara <yuya@tcha.org>
parents: 26017
diff changeset
    83
  > for head in [len(cl), 10000, -2, -10000, None]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    84
  >     print('%s:' % head, end=' ')
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
    85
  >     try:
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    86
  >         cl.reachableroots(0, [head], [0])
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    87
  >         print('uncaught buffer overflow?')
26018
c6115c30a376 reachableroots: verify type of each item of heads argument
Yuya Nishihara <yuya@tcha.org>
parents: 26017
diff changeset
    88
  >     except (IndexError, TypeError) as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    89
  >         print(inst)
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    90
  > print('good roots:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    91
  > for root in [0, len(cl) - 1, -1]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    92
  >     print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    93
  > print('out-of-range roots are ignored:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    94
  > for root in [len(cl), 10000, -2, -10000]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    95
  >     print('%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])))
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    96
  > print('bad roots:')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    97
  > for root in [None]:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
    98
  >     print('%s:' % root, end=' ')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
    99
  >     try:
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   100
  >         cl.reachableroots(root, [len(cl) - 1], [root])
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   101
  >         print('uncaught error?')
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   102
  >     except TypeError as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   103
  >         print(inst)
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   104
  > EOF
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   105
  good heads:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   106
  0: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   107
  1: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   108
  -1: []
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   109
  bad heads:
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   110
  2: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   111
  10000: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   112
  -2: head out of range
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   113
  -10000: head out of range
49052
34cdad07d06d test: deal with changed error message on python 3.10
Julien Cristau <jcristau@debian.org>
parents: 48876
diff changeset
   114
  None: (an integer is required( .got type NoneType.)?|'NoneType' object cannot be interpreted as an integer) (re)
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   115
  good roots:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   116
  0: [0]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   117
  1: [1]
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   118
  -1: [-1]
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   119
  out-of-range roots are ignored:
26094
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   120
  2: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   121
  10000: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   122
  -2: []
df41c7be16d6 reachableroots: construct and sort baseset in revset module
Yuya Nishihara <yuya@tcha.org>
parents: 26061
diff changeset
   123
  -10000: []
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   124
  bad roots:
49052
34cdad07d06d test: deal with changed error message on python 3.10
Julien Cristau <jcristau@debian.org>
parents: 48876
diff changeset
   125
  None: (an integer is required( .got type NoneType.)?|'NoneType' object cannot be interpreted as an integer) (re)
26017
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   126
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   127
  $ cd ..
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   128
44705659da94 reachableroots: verify integer range of heads argument (issue4775)
Yuya Nishihara <yuya@tcha.org>
parents: 26016
diff changeset
   129
Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
25859
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   130
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   131
  $ mkdir invalidparent
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   132
  $ cd invalidparent
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   133
40887
75728718257e test: make sure sparse-revlog does not interfer with test-parseindex.t
Boris Feld <boris.feld@octobus.net>
parents: 40812
diff changeset
   134
  $ hg clone --pull -q --config phases.publish=False ../a limit --config format.sparse-revlog=no
75728718257e test: make sure sparse-revlog does not interfer with test-parseindex.t
Boris Feld <boris.feld@octobus.net>
parents: 40812
diff changeset
   135
  $ hg clone --pull -q --config phases.publish=False ../a neglimit --config format.sparse-revlog=no
75728718257e test: make sure sparse-revlog does not interfer with test-parseindex.t
Boris Feld <boris.feld@octobus.net>
parents: 40812
diff changeset
   136
  $ hg clone --pull -q --config phases.publish=False ../a segv --config format.sparse-revlog=no
40812
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   137
  $ rm -R limit/.hg/cache neglimit/.hg/cache segv/.hg/cache
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   138
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   139
  $ "$PYTHON" <<EOF
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   140
  > data = open("limit/.hg/store/00changelog.i", "rb").read()
40812
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   141
  > poisons = [
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   142
  >     (b'limit', b'\0\0\0\x02'),
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   143
  >     (b'neglimit', b'\xff\xff\xff\xfe'),
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   144
  >     (b'segv', b'\0\x01\0\0'),
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   145
  > ]
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   146
  > for n, p in poisons:
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   147
  >     # corrupt p1 at rev0 and p2 at rev1
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   148
  >     d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:]
38087
307b19c7c043 py3: add b'' prefixes in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38079
diff changeset
   149
  >     open(n + b"/.hg/store/00changelog.i", "wb").write(d)
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   150
  > EOF
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   151
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38089
diff changeset
   152
  $ hg -R limit debugrevlogindex -f1 -c
37283
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   153
     rev flag     size   link     p1     p2       nodeid
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   154
       0 0000       62      0      2     -1 7c31755bf9b5
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   155
       1 0000       65      1      0      2 26333235a41c
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   156
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   157
  $ hg -R limit debugdeltachain -c
49221
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   158
      rev      p1      p2  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   159
        0       2      -1       1        1       -1    base         63         62         63   1.01613        63         0    0.00000
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   160
        1       0       2       2        1       -1    base         66         65         66   1.01538        66         0    0.00000
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   161
40812
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   162
  $ hg -R neglimit debugrevlogindex -f1 -c
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   163
     rev flag     size   link     p1     p2       nodeid
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   164
       0 0000       62      0     -2     -1 7c31755bf9b5
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   165
       1 0000       65      1      0     -2 26333235a41c
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   166
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38089
diff changeset
   167
  $ hg -R segv debugrevlogindex -f1 -c
37283
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   168
     rev flag     size   link     p1     p2       nodeid
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   169
       0 0000       62      0  65536     -1 7c31755bf9b5
d4e62df1c73d debugcommands: drop offset and length from debugindex by default
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37282
diff changeset
   170
       1 0000       65      1      0  65536 26333235a41c
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   171
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   172
  $ hg -R segv debugdeltachain -c
49221
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   173
      rev      p1      p2  chain# chainlen     prev   delta       size    rawsize  chainsize     ratio   lindist extradist extraratio
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   174
        0   65536      -1       1        1       -1    base         63         62         63   1.01613        63         0    0.00000
75d0775dce7f debugdeltachain: also display p1/p2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49052
diff changeset
   175
        1       0   65536       2        1       -1    base         66         65         66   1.01538        66         0    0.00000
37281
806b07d7c7d6 tests: use debugdeltachain where appropriate
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37280
diff changeset
   176
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   177
  $ cat <<EOF > test.py
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   178
  > import sys
41353
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
   179
  > from mercurial import changelog, pycompat, vfs
07ade2dc41db py3: port test-parseindex.t to Python 3
Augie Fackler <augie@google.com>
parents: 40887
diff changeset
   180
  > cl = changelog.changelog(vfs.vfs(pycompat.fsencode(sys.argv[1])))
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   181
  > n0, n1 = cl.node(0), cl.node(1)
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   182
  > ops = [
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   183
  >     ('reachableroots',
26053
b68c9d232db6 reachableroots: use internal "revstates" array to test if rev is a root
Yuya Nishihara <yuya@tcha.org>
parents: 26018
diff changeset
   184
  >      lambda: cl.index.reachableroots2(0, [1], [0], False)),
45131
61e7464477ac phases: sparsify phaseroots and phasesets
Joerg Sonnenberger <joerg@bec.de>
parents: 43025
diff changeset
   185
  >     ('compute_phases_map_sets', lambda: cl.computephases({1: {cl.node(0)}})),
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   186
  >     ('index_headrevs', lambda: cl.headrevs()),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   187
  >     ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   188
  >     ('find_deepest', lambda: cl.ancestor(n0, n1)),
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   189
  >     ]
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   190
  > for l, f in ops:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   191
  >     print(l + ':', end=' ')
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   192
  >     try:
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   193
  >         f()
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   194
  >         print('uncaught buffer overflow?')
38089
f0fadc5bea21 py3: use `except error as e` instead of `except error, e`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38087
diff changeset
   195
  >     except ValueError as inst:
38079
ce307af030a2 py3: use print as a function in tests/test-parseindex.t
Pulkit Goyal <7895pulkit@gmail.com>
parents: 38026
diff changeset
   196
  >         print(inst)
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   197
  > EOF
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   198
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   199
  $ "$PYTHON" test.py limit/.hg/store
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   200
  reachableroots: parent out of range
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   201
  compute_phases_map_sets: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   202
  index_headrevs: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   203
  find_gca_candidates: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   204
  find_deepest: parent out of range
40812
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   205
  $ "$PYTHON" test.py neglimit/.hg/store
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   206
  reachableroots: parent out of range
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   207
  compute_phases_map_sets: parent out of range
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   208
  index_headrevs: parent out of range
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   209
  find_gca_candidates: parent out of range
9cdd525d97b2 revlog: fix out-of-bounds access by negative parents read from revlog (SEC)
Yuya Nishihara <yuya@tcha.org>
parents: 40369
diff changeset
   210
  find_deepest: parent out of range
39707
5abc47d4ca6b tests: quote PYTHON usage
Matt Harbison <matt_harbison@yahoo.com>
parents: 39282
diff changeset
   211
  $ "$PYTHON" test.py segv/.hg/store
26016
c8d41c9c23c7 reachableroots: unify bail cases to raise exception correctly
Yuya Nishihara <yuya@tcha.org>
parents: 25859
diff changeset
   212
  reachableroots: parent out of range
25810
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   213
  compute_phases_map_sets: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   214
  index_headrevs: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   215
  find_gca_candidates: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   216
  find_deepest: parent out of range
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   217
82d6a35cf432 parsers: fix buffer overflow by invalid parent revision read from revlog
Yuya Nishihara <yuya@tcha.org>
parents: 16913
diff changeset
   218
  $ cd ..
25859
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   219
1619563959b3 tests: disable test of buffer overflow in parsers.c if --pure
Yuya Nishihara <yuya@tcha.org>
parents: 25810
diff changeset
   220
#endif