diff options
author | Guido van Rossum <guido@python.org> | 2000-03-03 14:51:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-03 14:51:11 (GMT) |
commit | 9428fa607b6edc7c5ef46814cd869291a8b4619e (patch) | |
tree | 602982d01d4577381fe9e0d541197da55af78932 /Tools | |
parent | 56359f591b361f41f661a14e5ed129bf8f22fa87 (diff) | |
download | cpython-9428fa607b6edc7c5ef46814cd869291a8b4619e.zip cpython-9428fa607b6edc7c5ef46814cd869291a8b4619e.tar.gz cpython-9428fa607b6edc7c5ef46814cd869291a8b4619e.tar.bz2 |
Patch by Tim Peters:
Changes the one regexp in PyParse capable of making the re module blow the C
stack when passed unreasonable <0.9 wink> program text. Jeremy Hylton
provoked this with a program of the form:
x = (1,
2,
... # 9997 lines deleted here
10000,
)
Programs "like this" will no longer (no matter how many lines they contain)
trigger re death. OTOH, you can now make another class of unreasonable
program that will take much longer to parse.
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/idle/PyParse.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Tools/idle/PyParse.py b/Tools/idle/PyParse.py index 9c3ae5c..23b995c 100644 --- a/Tools/idle/PyParse.py +++ b/Tools/idle/PyParse.py @@ -83,15 +83,13 @@ _closere = re.compile(r""" \b """, re.VERBOSE).match -# Chew up non-special chars as quickly as possible, but retaining -# enough info to determine the last non-ws char seen; if match is -# successful, and m.group(1) isn't None, m.end(1) less 1 is the -# index of the last non-ws char matched. +# Chew up non-special chars as quickly as possible. If match is +# successful, m.end() less 1 is the index of the last boring char +# matched. If match is unsuccessful, the string starts with an +# interesting char. _chew_ordinaryre = re.compile(r""" - (?: \s+ - | ( [^\s[\](){}#'"\\]+ ) - )+ + [^[\](){}#'"\\]+ """, re.VERBOSE).match # Build translation table to map uninteresting chars to "x", open @@ -386,10 +384,14 @@ class Parser: # suck up all except ()[]{}'"#\\ m = _chew_ordinaryre(str, p, q) if m: - i = m.end(1) - 1 # last non-ws (if any) + # we skipped at least one boring char + p = m.end() + # back up over totally boring whitespace + i = p-1 # index of last boring char + while i >= 0 and str[i] in " \t\n": + i = i-1 if i >= 0: lastch = str[i] - p = m.end() if p >= q: break |