Show More
@@ -1,185 +1,185 b'' | |||
|
1 | 1 | revlog.parseindex must be able to parse the index file even if |
|
2 | 2 | an index entry is split between two 64k blocks. The ideal test |
|
3 | 3 | would be to create an index file with inline data where |
|
4 | 4 | 64k < size < 64k + 64 (64k is the size of the read buffer, 64 is |
|
5 | 5 | the size of an index entry) and with an index entry starting right |
|
6 | 6 | before the 64k block boundary, and try to read it. |
|
7 | 7 | We approximate that by reducing the read buffer to 1 byte. |
|
8 | 8 | |
|
9 | 9 | $ hg init a |
|
10 | 10 | $ cd a |
|
11 | 11 | $ echo abc > foo |
|
12 | 12 | $ hg add foo |
|
13 | 13 | $ hg commit -m 'add foo' |
|
14 | 14 | $ echo >> foo |
|
15 | 15 | $ hg commit -m 'change foo' |
|
16 | 16 | $ hg log -r 0: |
|
17 | 17 | changeset: 0:7c31755bf9b5 |
|
18 | 18 | user: test |
|
19 | 19 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
20 | 20 | summary: add foo |
|
21 | 21 | |
|
22 | 22 | changeset: 1:26333235a41c |
|
23 | 23 | tag: tip |
|
24 | 24 | user: test |
|
25 | 25 | date: Thu Jan 01 00:00:00 1970 +0000 |
|
26 | 26 | summary: change foo |
|
27 | 27 | |
|
28 | 28 | $ cat >> test.py << EOF |
|
29 | 29 | > from mercurial import changelog, vfs |
|
30 | 30 | > from mercurial.node import * |
|
31 | 31 | > |
|
32 | 32 | > class singlebyteread(object): |
|
33 | 33 | > def __init__(self, real): |
|
34 | 34 | > self.real = real |
|
35 | 35 | > |
|
36 | 36 | > def read(self, size=-1): |
|
37 | 37 | > if size == 65536: |
|
38 | 38 | > size = 1 |
|
39 | 39 | > return self.real.read(size) |
|
40 | 40 | > |
|
41 | 41 | > def __getattr__(self, key): |
|
42 | 42 | > return getattr(self.real, key) |
|
43 | 43 | > |
|
44 | 44 | > def opener(*args): |
|
45 | 45 | > o = vfs.vfs(*args) |
|
46 | > def wrapper(*a): | |
|
47 | > f = o(*a) | |
|
46 | > def wrapper(*a, **kwargs): | |
|
47 | > f = o(*a, **kwargs) | |
|
48 | 48 | > return singlebyteread(f) |
|
49 | 49 | > return wrapper |
|
50 | 50 | > |
|
51 | 51 | > cl = changelog.changelog(opener('.hg/store')) |
|
52 | 52 | > print len(cl), 'revisions:' |
|
53 | 53 | > for r in cl: |
|
54 | 54 | > print short(cl.node(r)) |
|
55 | 55 | > EOF |
|
56 | 56 | $ $PYTHON test.py |
|
57 | 57 | 2 revisions: |
|
58 | 58 | 7c31755bf9b5 |
|
59 | 59 | 26333235a41c |
|
60 | 60 | |
|
61 | 61 | $ cd .. |
|
62 | 62 | |
|
63 | 63 | #if no-pure |
|
64 | 64 | |
|
65 | 65 | Test SEGV caused by bad revision passed to reachableroots() (issue4775): |
|
66 | 66 | |
|
67 | 67 | $ cd a |
|
68 | 68 | |
|
69 | 69 | $ $PYTHON <<EOF |
|
70 | 70 | > from mercurial import changelog, vfs |
|
71 | 71 | > cl = changelog.changelog(vfs.vfs('.hg/store')) |
|
72 | 72 | > print 'good heads:' |
|
73 | 73 | > for head in [0, len(cl) - 1, -1]: |
|
74 | 74 | > print'%s: %r' % (head, cl.reachableroots(0, [head], [0])) |
|
75 | 75 | > print 'bad heads:' |
|
76 | 76 | > for head in [len(cl), 10000, -2, -10000, None]: |
|
77 | 77 | > print '%s:' % head, |
|
78 | 78 | > try: |
|
79 | 79 | > cl.reachableroots(0, [head], [0]) |
|
80 | 80 | > print 'uncaught buffer overflow?' |
|
81 | 81 | > except (IndexError, TypeError) as inst: |
|
82 | 82 | > print inst |
|
83 | 83 | > print 'good roots:' |
|
84 | 84 | > for root in [0, len(cl) - 1, -1]: |
|
85 | 85 | > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])) |
|
86 | 86 | > print 'out-of-range roots are ignored:' |
|
87 | 87 | > for root in [len(cl), 10000, -2, -10000]: |
|
88 | 88 | > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root])) |
|
89 | 89 | > print 'bad roots:' |
|
90 | 90 | > for root in [None]: |
|
91 | 91 | > print '%s:' % root, |
|
92 | 92 | > try: |
|
93 | 93 | > cl.reachableroots(root, [len(cl) - 1], [root]) |
|
94 | 94 | > print 'uncaught error?' |
|
95 | 95 | > except TypeError as inst: |
|
96 | 96 | > print inst |
|
97 | 97 | > EOF |
|
98 | 98 | good heads: |
|
99 | 99 | 0: [0] |
|
100 | 100 | 1: [0] |
|
101 | 101 | -1: [] |
|
102 | 102 | bad heads: |
|
103 | 103 | 2: head out of range |
|
104 | 104 | 10000: head out of range |
|
105 | 105 | -2: head out of range |
|
106 | 106 | -10000: head out of range |
|
107 | 107 | None: an integer is required |
|
108 | 108 | good roots: |
|
109 | 109 | 0: [0] |
|
110 | 110 | 1: [1] |
|
111 | 111 | -1: [-1] |
|
112 | 112 | out-of-range roots are ignored: |
|
113 | 113 | 2: [] |
|
114 | 114 | 10000: [] |
|
115 | 115 | -2: [] |
|
116 | 116 | -10000: [] |
|
117 | 117 | bad roots: |
|
118 | 118 | None: an integer is required |
|
119 | 119 | |
|
120 | 120 | $ cd .. |
|
121 | 121 | |
|
122 | 122 | Test corrupted p1/p2 fields that could cause SEGV at parsers.c: |
|
123 | 123 | |
|
124 | 124 | $ mkdir invalidparent |
|
125 | 125 | $ cd invalidparent |
|
126 | 126 | |
|
127 | 127 | $ hg clone --pull -q --config phases.publish=False ../a limit |
|
128 | 128 | $ hg clone --pull -q --config phases.publish=False ../a segv |
|
129 | 129 | $ rm -R limit/.hg/cache segv/.hg/cache |
|
130 | 130 | |
|
131 | 131 | $ $PYTHON <<EOF |
|
132 | 132 | > data = open("limit/.hg/store/00changelog.i", "rb").read() |
|
133 | 133 | > for n, p in [('limit', '\0\0\0\x02'), ('segv', '\0\x01\0\0')]: |
|
134 | 134 | > # corrupt p1 at rev0 and p2 at rev1 |
|
135 | 135 | > d = data[:24] + p + data[28:127 + 28] + p + data[127 + 32:] |
|
136 | 136 | > open(n + "/.hg/store/00changelog.i", "wb").write(d) |
|
137 | 137 | > EOF |
|
138 | 138 | |
|
139 | 139 | $ hg debugindex -f1 limit/.hg/store/00changelog.i |
|
140 | 140 | rev flag offset length size base link p1 p2 nodeid |
|
141 | 141 | 0 0000 0 63 62 0 0 2 -1 7c31755bf9b5 |
|
142 | 142 | 1 0000 63 66 65 1 1 0 2 26333235a41c |
|
143 | 143 | $ hg debugindex -f1 segv/.hg/store/00changelog.i |
|
144 | 144 | rev flag offset length size base link p1 p2 nodeid |
|
145 | 145 | 0 0000 0 63 62 0 0 65536 -1 7c31755bf9b5 |
|
146 | 146 | 1 0000 63 66 65 1 1 0 65536 26333235a41c |
|
147 | 147 | |
|
148 | 148 | $ cat <<EOF > test.py |
|
149 | 149 | > import sys |
|
150 | 150 | > from mercurial import changelog, vfs |
|
151 | 151 | > cl = changelog.changelog(vfs.vfs(sys.argv[1])) |
|
152 | 152 | > n0, n1 = cl.node(0), cl.node(1) |
|
153 | 153 | > ops = [ |
|
154 | 154 | > ('reachableroots', |
|
155 | 155 | > lambda: cl.index.reachableroots2(0, [1], [0], False)), |
|
156 | 156 | > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])), |
|
157 | 157 | > ('index_headrevs', lambda: cl.headrevs()), |
|
158 | 158 | > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)), |
|
159 | 159 | > ('find_deepest', lambda: cl.ancestor(n0, n1)), |
|
160 | 160 | > ] |
|
161 | 161 | > for l, f in ops: |
|
162 | 162 | > print l + ':', |
|
163 | 163 | > try: |
|
164 | 164 | > f() |
|
165 | 165 | > print 'uncaught buffer overflow?' |
|
166 | 166 | > except ValueError, inst: |
|
167 | 167 | > print inst |
|
168 | 168 | > EOF |
|
169 | 169 | |
|
170 | 170 | $ $PYTHON test.py limit/.hg/store |
|
171 | 171 | reachableroots: parent out of range |
|
172 | 172 | compute_phases_map_sets: parent out of range |
|
173 | 173 | index_headrevs: parent out of range |
|
174 | 174 | find_gca_candidates: parent out of range |
|
175 | 175 | find_deepest: parent out of range |
|
176 | 176 | $ $PYTHON test.py segv/.hg/store |
|
177 | 177 | reachableroots: parent out of range |
|
178 | 178 | compute_phases_map_sets: parent out of range |
|
179 | 179 | index_headrevs: parent out of range |
|
180 | 180 | find_gca_candidates: parent out of range |
|
181 | 181 | find_deepest: parent out of range |
|
182 | 182 | |
|
183 | 183 | $ cd .. |
|
184 | 184 | |
|
185 | 185 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now