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