#!/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.8477200000002549.516150000000042418.56008000000021406.396782420.67970000000011264.4902999999999795.81993999999997991.968870000000041026.1800600000001752.188959999999951020.11370.38677.70000000000074715.3999999999996856.8931.9736.2792.5361.5296.3448.63087.5490.221206.799999999999342.2819.2326.60000000000002686.6200.1301.60000000000002291.071539999999971348.8663700000002108.7191.980.676199999999994650.0048600000000162.52047000000000335.9064899999999981745.3451.66242741.63382937.472610000000032245.777721723.0296499999999494.547464322.5551915.128253.206189999999999944.86723999999999553.099980000000002000210739.32737.61195.9000000000001695.324.26210.099000000000255.1060000000000023397.54973000000022214.27126.6300800000000122.3779299999999994.9000000000000004118.481.90000000000000637.056125160.8351899999998791.919499999999973026.84715000000011661.41942999999993426.975971340.17658000000011236.88713000000011101.93315999999981234.35221027.27470999999991398.91743.911908.16182.51425.81219.4000000000001795.1943.7646.9375.7520.53818.4545.425738.5518.200000000000051054.2429.9822243.2375.2380.170549999999991863.6562900000001134258.39999999999998138.23195000000001807.132349999999973.43782999999999991.67280000000000012602.1612.20000000000005733.52331.22154999999981156.04418999999982553.29687000000012175.1782000000003650.8355500000000128.136.37276999999999613.4179999999999993.395449999999999945.92504000000000335.24217000000000200024.801082.59999999999992696.11348.4953.933.69917.2019999999993116.798534435.05580000000015402.5240000000003188.4418399999999821.5819100000000018.6162.697.187.6377700000000034817.8854499999998604.885390000000032780.28604999999971346.72383252.87199000000011457.33639999999991208.73475000000011118.29085000000011172.1987099999999767.858740000000011235.90000000000011635.3119306063.813781026.5890.3873.2564329.6567.200000000000053615.1586.2000000000000525638.1470.91040529.70000000000005800.8303.3346.2277.421561964.2349299999998146.6212130.24814999999998922.004560000000080-4.1710000000000004E-22596.4611.29999999999995687.32084.53529000000031117.512322605.899862486.51224618.5327600000000536.79999999999999732.3723612.285054.414760000000000241.80333000000000352.700018.89999999999999901094.903382978.71970999999981335.7084199999999887.0441600000000336.79999999999999714431.694141.635500000000014842.54870000000036008.016009999999415.11460000000000121.62984999999999818155.3000000000000193.572.9039999999999963033.08214999999975561903.82435000000011108.810872193.589951196.8404800000001747.538000000000011231.13069789.43528000000003646.97218999999996964.11317.98486.20000000000074384.5781.2752.7685.2489.5336.2206.5496.12312.1999999999998464.618972.359850000001423.1672.1494.2378.7282235.8236.620061261.7034099999998154.19999999999999160.3000000000000168.129050000000007606.94815000000006001959.3608.4643.42288.19999999999981021.12235.51817.7522.4027.605.547.829.900019.50710.72670.70010999999981083.5999999999999660.328.711174.625184.1973924.04360999999975137.2020000000002164.7719999999999919.9630000000000019.1999999999999993109.3481100000000178.40000000000000685.3519000000000012348.4110299999998863.195000000000051631.019551215.36560000000011866.610151230.2637732.22994999999992821.79359999999997750.92511999999999699.01962000000003713.41135.09999999999997439.73534.2928.1646.49180000000001736.99014999999997599.6414.3244.5409.11818.3725.519796.099999999999358.7499.7306538242.9199.4302.96810999999997873.4226200000000592.3141.197.238369999999989346.42796999999996001375.3550.99969999999996623.457920000000061461.1639.299999999999951666.41022.7412.4035.29999999999999704.265.492353.900021.60730.81501.4532400000001590.70000000000005659.825.19427.9609999999993139.901999999999992868.317384562.723237.3839999999999926.16499999999999916.100000000000001109.2981353.164.1560000000000061698.6732200000001422.88835935.23282999999992659.325849999999951174.1897400000003662.85299999999995424.16584999999998489.73676467.35383999999999371.96517999999998432.28854806.32398.1388.4404.7433.7409215.9187.7269.21392.5543.7000000000000513044.68476456.7919.1351.5576294.8302.10000000000002201.009469999999991115.913029999999962.678.900000000000006136.55001999999999572.14634000000001002077.8000000000002590.29999999999995527.299999999999951434.1621.700000000000051587.3950.2399033.70000000000000304.099999999999999656.844.500018.20734.61506.1756.3847.827.12737.37575.7442607.19999999999983022.509-21.3917.79500000000000221.2109.959.755.4364225.5859299999993675.625999999999982747.22817000000031603.481623009.43719000000011546.15619999999991231.98575000000011109.73465999999981232.73087000000011011.595721411.61632.410689.95881.41284.21353.89131268.5441.2486.1501.4388264326108.1476.1738.3399.2895.8276.89999999999998421.6256.921670000000011238.1414499999998116.5265.8999999999999893.734999999999999639.80600000000004002268.3000000000002658.7820.22357.6955.62622.91494.6632.6033.29999999999999704.758.760.900021.70747.82735.31104.8892.930.48159.1589999999997155.889999999999994252.55759.9040000000005247.5339999999999932.13727.5130.1999999999999967.400000000000006125.549000000000013860.9429755.692862645.05511492.78442999999992716.752361590.870481144.321781053.323471210.4103799999998772.793249999999941196.09999999999991545.79414.55360.31457.91035.8799.9928.9525.29999999999995260.60000000000002527.13092.4614.7999999999999520765.7571.20000000000005868.6469.4575.1255.3343.9263.682841400.75326115.2248.791.494751.09500000000003002332.1999999999998651.9823.52188.1999999999998848.72601.51516.5587.503304.565.552.700026.70706.82441.41089.5999999999999780.333.611480.956251.212999999999994275.77088.8969999999999285.0559999999999836.52499999999999920.399999999999999128.472.099999999999994147.330999999999994230824.12770.14899999999991493.92960.41513.51127.6327511701293.65900000000017111224.3169511226.95616.71139.21162910.21061.4000000000001419283.86003118.2668.224134.5490.1908.5485616.4302410.4237.91343.5120257.5107.6614754.33665000000008002108.6682.9814.52296.9944.12754.41400601.4027.203.658.555.8000230743.12782.31420820331080023847507452.3164.130.12099999999999918142701591955620.116301062.90000000000011397960530910610625775970490028501000550930530420190500180051512700532.20000000000005400420430295171.921771088140613700010156356503700905.723501150397019.89421487603305704.1261016949152545474000015062526901828.764523620020044003062.4115242311050852175488.31180860145090043578047045066596547002550890465738400315150375122545012260492.63603403852151351506759011545280009256255952682.310001798.41050402.7019.89421487603305704.12610169491525454230000150597.299999999999952176.199999999999810015002350008529001805.28516199636151975418.314359001201995450710520440600102550002400590500715380300105375170041012070396.337031030520516016570095110603400010555755852550973.31869.51030403.5019.89421487603305704.1261016949152545453000010055923851275.09999999999995102050008530001813.5651815874915' 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()