#!/usr/bin/env python
# Test case to demonstrate pyexpat crash under Mac OS X 10.6.8.
# This segfaults both 2.6.1 bundled with the OS and 2.7.2 as
# provided by www.python.org. (It also segfaults 2.6.7 on the
# development branch of NetBSD [5.99.47], but not the most recent
# stable branch [5.1_STABLE], interestingly enough...)
from __future__ import print_function
import string
import sys
import xml.parsers.expat
def start_element(name, attrs):
pass
def end_element(name):
pass
def char_data(data):
pass
ep = None
def instantiate_parser():
"""Create an Expat parser instance (intended for re-use across multiple
calls to its Parse() method) and attach generic delegate methods."""
global ep
try:
ep = xml.parsers.expat.ParserCreate()
ep.StartElementHandler = start_element
ep.EndElementHandler = end_element
ep.CharacterDataHandler = char_data
except xml.parsers.expat.ExpatError as error:
print("An error occurred during Expat set-up. " \
+ "Error ID: " + str(error.code) \
+ ". Error message: " \
+ xml.parsers.expat.ErrorString(error.code), file=sys.stderr)
def destroy_parser():
"""Invoke a final call to the Expat parser's Parse() method to pass the
IsFinal value of True so it will destroy itself."""
global ep
if ep != None:
try:
ep.Parse('', True)
except xml.parsers.expat.ExpatError as error:
print("An error occurred during XML parsing. " \
+ "Error ID: " + str(error.code) \
+ ". Error message: " \
+ xml.parsers.expat.ErrorString(error.code), file=sys.stderr)
finally:
ep = None
def parse_doc(input_string):
"""Accepts a string representing relevant data from an XML file and
initiates the extraction of relevant data via proxy methods."""
global ep
if ep == None:
instantiate_parser()
try:
ep.Parse(input_string, False)
except xml.parsers.expat.ExpatError as error:
print("An error occurred during XML parsing. " \
+ "Error ID: " + str(error.code) \
+ ". Error message: " \
+ xml.parsers.expat.ErrorString(error.code), file=sys.stderr)
print("Line number:", ep.ErrorLineNumber, file=sys.stderr)
smallest_test_file = \
'' \
+ ''
small_test_file = \
'' \
+ ''
large_test_file = \
'' \
+ '3782.8477200000002 |
549.51615000000004 |
2418.5600800000002 |
1406.39678 |
2420.6797000000001 |
1264.4902999999999 |
795.81993999999997 |
991.96887000000004 |
1026.1800600000001 |
752.18895999999995 |
1020.1 |
1370.3 |
8677.7000000000007 |
4715.3999999999996 |
856.8 |
931.9 |
736.2 |
792.5 |
361.5 |
296.3 |
448.6 |
3087.5 |
490.2 |
21206.799999999999 |
342.2 |
819.2 |
326.60000000000002 |
686.6 |
200.1 |
301.60000000000002 |
291.07153999999997 |
1348.8663700000002 |
108.7 |
191.9 |
80.676199999999994 |
650.00486000000001 |
62.520470000000003 |
35.906489999999998 |
1745.3 |
451.6 |
624 |
2741.63382 |
937.47261000000003 |
2245.77772 |
1723.0296499999999 |
494.54746 |
43 |
22.55519 |
15.12825 |
3.2061899999999999 |
44.867239999999995 |
53.099980000000002 |
0 |
0 |
0 |
21 |
0 |
739.3 |
2737.6 |
1195.9000000000001 |
695.3 |
24.2 |
6210.0990000000002 |
55.106000000000002 |
3397.5497300000002 |
2214.27 |
126.63008000000001 |
22.377929999999999 |
4.9000000000000004 |
118.4 |
81.900000000000006 |
37.05612 |
5160.8351899999998 |
791.91949999999997 |
3026.8471500000001 |
1661.4194299999999 |
3426.97597 |
1340.1765800000001 |
1236.8871300000001 |
1101.9331599999998 |
1234.3522 |
1027.2747099999999 |
1398.9 |
1743.9 |
11908.1 |
6182.5 |
1425.8 |
1219.4000000000001 |
795.1 |
943.7 |
646.9 |
375.7 |
520.5 |
3818.4 |
545.4 |
25738.5 |
518.20000000000005 |
1054.2 |
429.9 |
822 |
243.2 |
375.2 |
380.17054999999999 |
1863.6562900000001 |
134 |
258.39999999999998 |
138.23195000000001 |
807.13234999999997 |
3.4378299999999999 |
1.6728000000000001 |
2602.1 |
612.20000000000005 |
733.5 |
2331.2215499999998 |
1156.0441899999998 |
2553.2968700000001 |
2175.1782000000003 |
650.83555000000001 |
28.1 |
36.372769999999996 |
13.417999999999999 |
3.3954499999999999 |
45.925040000000003 |
35.242170000000002 |
0 |
0 |
0 |
24.8 |
0 |
1082.5999999999999 |
2696.1 |
1348.4 |
953.9 |
33.6 |
9917.2019999999993 |
116.79853 |
4435.0558000000001 |
5402.5240000000003 |
188.44183999999998 |
21.581910000000001 |
8.6 |
162.6 |
97.1 |
87.637770000000003 |
4817.8854499999998 |
604.88539000000003 |
2780.2860499999997 |
1346.7238 |
3252.8719900000001 |
1457.3363999999999 |
1208.7347500000001 |
1118.2908500000001 |
1172.1987099999999 |
767.85874000000001 |
1235.9000000000001 |
1635.3 |
11930 |
6063.8 |
1378 |
1026.5 |
890.3 |
873.2 |
564 |
329.6 |
567.20000000000005 |
3615.1 |
586.20000000000005 |
25638.1 |
470.9 |
1040 |
529.70000000000005 |
800.8 |
303.3 |
346.2 |
277.42156 |
1964.2349299999998 |
146.6 |
212 |
130.24814999999998 |
922.00456000000008 |
0 |
-4.1710000000000004E-2 |
2596.4 |
611.29999999999995 |
687.3 |
2084.5352900000003 |
1117.51232 |
2605.89986 |
2486.51224 |
618.53276000000005 |
36.799999999999997 |
32.37236 |
12.28505 |
4.4147600000000002 |
41.803330000000003 |
52.7 |
0 |
0 |
0 |
18.899999999999999 |
0 |
1094.90338 |
2978.7197099999998 |
1335.7084199999999 |
887.04416000000003 |
36.799999999999997 |
14431.694 |
141.63550000000001 |
4842.5487000000003 |
6008.0160099999994 |
15.114600000000001 |
21.629849999999998 |
18 |
155.30000000000001 |
93.5 |
72.903999999999996 |
3033.0821499999997 |
556 |
1903.8243500000001 |
1108.81087 |
2193.58995 |
1196.8404800000001 |
747.53800000000001 |
1231.13069 |
789.43528000000003 |
646.97218999999996 |
964.1 |
1317.9 |
8486.2000000000007 |
4384.5 |
781.2 |
752.7 |
685.2 |
489.5 |
336.2 |
206.5 |
496.1 |
2312.1999999999998 |
464.6 |
18972.359850000001 |
423.1 |
672.1 |
494.2 |
378.7 |
282 |
235.8 |
236.62006 |
1261.7034099999998 |
154.19999999999999 |
160.30000000000001 |
68.129050000000007 |
606.94815000000006 |
0 |
0 |
1959.3 |
608.4 |
643.4 |
2288.1999999999998 |
1021.1 |
2235.5 |
1817.7 |
522.4 |
0 |
27.6 |
0 |
5.5 |
47.8 |
29.9 |
0 |
0 |
0 |
19.5 |
0 |
710.7 |
2670.7001099999998 |
1083.5999999999999 |
660.3 |
28.7 |
11174.625 |
184.197 |
3924.0436099999997 |
5137.2020000000002 |
164.77199999999999 |
19.963000000000001 |
9.1999999999999993 |
109.34811000000001 |
78.400000000000006 |
85.351900000000001 |
2348.4110299999998 |
863.19500000000005 |
1631.01955 |
1215.3656000000001 |
1866.61015 |
1230.2637 |
732.22994999999992 |
821.79359999999997 |
750.92511999999999 |
699.01962000000003 |
713.4 |
1135.0999999999999 |
7439.7 |
3534.2 |
928.1 |
646.49180000000001 |
736.99014999999997 |
599.6 |
414.3 |
244.5 |
409.1 |
1818.3 |
725.5 |
19796.099999999999 |
358.7 |
499.7 |
306 |
538 |
242.9 |
199.4 |
302.96810999999997 |
873.42262000000005 |
92.3 |
141.1 |
97.238369999999989 |
346.42796999999996 |
0 |
0 |
1375.3 |
550.99969999999996 |
623.45792000000006 |
1461.1 |
639.29999999999995 |
1666.4 |
1022.7 |
412.4 |
0 |
35.299999999999997 |
0 |
4.2 |
65.4923 |
53.9 |
0 |
0 |
0 |
21.6 |
0 |
730.8 |
1501.4532400000001 |
590.70000000000005 |
659.8 |
25.1 |
9427.9609999999993 |
139.90199999999999 |
2868.31738 |
4562.723 |
237.38399999999999 |
26.164999999999999 |
16.100000000000001 |
109.29813 |
53.1 |
64.156000000000006 |
1698.6732200000001 |
422.88835 |
935.23282999999992 |
659.32584999999995 |
1174.1897400000003 |
662.85299999999995 |
424.16584999999998 |
489.73676 |
467.35383999999999 |
371.96517999999998 |
432.2 |
885 |
4806.3 |
2398.1 |
388.4 |
404.7 |
433.7 |
409 |
215.9 |
187.7 |
269.2 |
1392.5 |
543.70000000000005 |
13044.68476 |
456.7 |
919.1 |
351.5 |
576 |
294.8 |
302.10000000000002 |
201.00946999999999 |
1115.9130299999999 |
62.6 |
78.900000000000006 |
136.55001999999999 |
572.14634000000001 |
0 |
0 |
2077.8000000000002 |
590.29999999999995 |
527.29999999999995 |
1434.1 |
621.70000000000005 |
1587.3 |
950.2 |
399 |
0 |
33.700000000000003 |
0 |
4.0999999999999996 |
56.8 |
44.5 |
0 |
0 |
0 |
18.2 |
0 |
734.6 |
1506.1 |
756.3 |
847.8 |
27.1 |
2737.375 |
75.744 |
2607.1999999999998 |
3022.509 |
-21.39 |
17.795000000000002 |
21.2 |
109.9 |
59.7 |
55.436 |
4225.5859299999993 |
675.62599999999998 |
2747.2281700000003 |
1603.48162 |
3009.4371900000001 |
1546.1561999999999 |
1231.9857500000001 |
1109.7346599999998 |
1232.7308700000001 |
1011.59572 |
1411.6 |
1632.4 |
10689.9 |
5881.4 |
1284.2 |
1353.8 |
913 |
1268.5 |
441.2 |
486.1 |
501.4 |
3882 |
643 |
26108.1 |
476.1 |
738.3 |
399.2 |
895.8 |
276.89999999999998 |
421.6 |
256.92167000000001 |
1238.1414499999998 |
116.5 |
265.89999999999998 |
93.734999999999999 |
639.80600000000004 |
0 |
0 |
2268.3000000000002 |
658.7 |
820.2 |
2357.6 |
955.6 |
2622.9 |
1494.6 |
632.6 |
0 |
33.299999999999997 |
0 |
4.7 |
58.7 |
60.9 |
0 |
0 |
0 |
21.7 |
0 |
747.8 |
2735.3 |
1104.8 |
892.9 |
30.4 |
8159.1589999999997 |
155.88999999999999 |
4252.5 |
5759.9040000000005 |
247.53399999999999 |
32.137 |
27.5 |
130.19999999999999 |
67.400000000000006 |
125.54900000000001 |
3860.9429 |
755.69286 |
2645.0551 |
1492.7844299999999 |
2716.75236 |
1590.87048 |
1144.32178 |
1053.32347 |
1210.4103799999998 |
772.79324999999994 |
1196.0999999999999 |
1545.7 |
9414.5 |
5360.3 |
1457.9 |
1035.8 |
799.9 |
928.9 |
525.29999999999995 |
260.60000000000002 |
527.1 |
3092.4 |
614.79999999999995 |
20765.7 |
571.20000000000005 |
868.6 |
469.4 |
575.1 |
255.3 |
343.9 |
263.68284 |
1400.75326 |
115.2 |
248.7 |
91.494 |
751.09500000000003 |
0 |
0 |
2332.1999999999998 |
651.9 |
823.5 |
2188.1999999999998 |
848.7 |
2601.5 |
1516.5 |
587.5 |
0 |
33 |
0 |
4.5 |
65.5 |
52.7 |
0 |
0 |
0 |
26.7 |
0 |
706.8 |
2441.4 |
1089.5999999999999 |
780.3 |
33.6 |
11480.956 |
251.21299999999999 |
4275.7 |
7088.8969999999999 |
285.05599999999998 |
36.524999999999999 |
20.399999999999999 |
128.4 |
72.099999999999994 |
147.33099999999999 |
4230 |
824.1 |
2770.1489999999999 |
1493.9 |
2960.4 |
1513.5 |
1127.63275 |
1170 |
1293.6590000000001 |
711 |
1224.3 |
1695 |
11226.9 |
5616.7 |
1139.2 |
1162 |
910.2 |
1061.4000000000001 |
419 |
283.8 |
600 |
3118.2 |
668.2 |
24134.5 |
490.1 |
908.5 |
485 |
616.4 |
302 |
410.4 |
237.9 |
1343.5 |
120 |
257.5 |
107.6614 |
754.33665000000008 |
0 |
0 |
2108.6 |
682.9 |
814.5 |
2296.9 |
944.1 |
2754.4 |
1400 |
601.4 |
0 |
27.2 |
0 |
3.6 |
58.5 |
55.8 |
0 |
0 |
0 |
23 |
0 |
743.1 |
2782.3 |
1420 |
820 |
33 |
10800 |
238 |
4750 |
7452.3 |
164.1 |
30.120999999999999 |
18 |
142 |
70 |
159 |
1955 |
620.1 |
1630 |
1062.9000000000001 |
1397 |
960 |
530 |
910 |
610 |
625 |
775 |
970 |
4900 |
2850 |
1000 |
550 |
930 |
530 |
420 |
190 |
500 |
1800 |
515 |
12700 |
532.20000000000005 |
400 |
420 |
430 |
295 |
171.9 |
217 |
710 |
88 |
140 |
61 |
370 |
0 |
0 |
1015 |
635 |
650 |
3700 |
905.7 |
2350 |
1150 |
397 |
0 |
19.894214876033057 |
0 |
4.1261016949152545 |
47 |
40 |
0 |
0 |
0 |
15 |
0 |
625 |
2690 |
1828.7 |
645 |
23 |
6200 |
200 |
4400 |
3062.4 |
115 |
24 |
23 |
110 |
50 |
85 |
2175 |
488.3 |
1180 |
860 |
1450 |
900 |
435 |
780 |
470 |
450 |
665 |
965 |
4700 |
2550 |
890 |
465 |
738 |
400 |
315 |
150 |
375 |
1225 |
450 |
12260 |
492.6 |
360 |
340 |
385 |
215 |
135 |
150 |
675 |
90 |
115 |
45 |
280 |
0 |
0 |
925 |
625 |
595 |
2682.3 |
1000 |
1798.4 |
1050 |
402.7 |
0 |
19.894214876033057 |
0 |
4.1261016949152545 |
42 |
30 |
0 |
0 |
0 |
15 |
0 |
597.29999999999995 |
2176.1999999999998 |
1001 |
500 |
23 |
5000 |
85 |
2900 |
1805.2 |
85 |
16 |
19 |
96 |
36 |
15 |
1975 |
418.3 |
1435 |
900 |
1201 |
995 |
450 |
710 |
520 |
440 |
600 |
1025 |
5000 |
2400 |
590 |
500 |
715 |
380 |
300 |
105 |
375 |
1700 |
410 |
12070 |
396.3 |
370 |
310 |
305 |
205 |
160 |
165 |
700 |
95 |
110 |
60 |
340 |
0 |
0 |
1055 |
575 |
585 |
2550 |
973.3 |
1869.5 |
1030 |
403.5 |
0 |
19.894214876033057 |
0 |
4.1261016949152545 |
45 |
30 |
0 |
0 |
0 |
10 |
0 |
559 |
2385 |
1275.0999999999999 |
510 |
20 |
5000 |
85 |
3000 |
1813.5 |
65 |
18 |
15 |
87 |
49 |
15 |
'
if __name__ == "__main__":
# This won't cause a crash...
parse_doc(smallest_test_file) # Initial, successful parse
parse_doc(large_test_file) # First triggering of a parser error
parse_doc(large_test_file) # Second triggering of a parser error
destroy_parser()
# Adding a bit more to the first file submitted causes a crash...
parse_doc(small_test_file) # Initial, successful parse
parse_doc(large_test_file) # First triggering of a parser error
parse_doc(large_test_file) # Second triggering of a parser error
destroy_parser()