Skip to content

Commit d9278a5

Browse files
committed
Fortran: fix catastrophic backtracking
\\\\|\\. is like \\. but causes catastrophic backtracking inside (...)* .
1 parent 9bd072d commit d9278a5

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Version 2.13.0
2424
* Coq: add some common keywords, improve recognition of ``Set``
2525
and qualified identifiers (#2158)
2626
* F*: Allow C-style comments anywhere in a line
27+
* Fortran: fix catastrophic backtracking with backslashes in strings
28+
(#2194)
2729
* Go: add support for generics (#2167)
2830
* Inform: update for version 6.40 (#2190)
2931
* Isabelle: recognize cartouches (#2089)

pygments/lexers/fortran.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ class FortranLexer(RegexLexer):
157157
],
158158

159159
'strings': [
160-
(r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
161-
(r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
160+
(r'(?s)"(\\[0-7]+|\\[^0-7\n]|[^"\\])*"', String.Double),
161+
(r"(?s)'(\\[0-7]+|\\[^0-7\n]|[^'\\])*'", String.Single),
162162
],
163163

164164
'nums': [
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---input---
2+
! Bad string, there isn't an even number of backslashes.
3+
! This should not cause catastrophic backtracking.
4+
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
5+
6+
---tokens---
7+
"! Bad string, there isn't an even number of backslashes.\n" Comment
8+
9+
'! This should not cause catastrophic backtracking.\n' Comment
10+
11+
"'" Error
12+
'\\' Error
13+
'\\' Error
14+
'\\' Error
15+
'\\' Error
16+
'\\' Error
17+
'\\' Error
18+
'\\' Error
19+
'\\' Error
20+
'\\' Error
21+
'\\' Error
22+
'\\' Error
23+
'\\' Error
24+
'\\' Error
25+
'\\' Error
26+
'\\' Error
27+
'\\' Error
28+
'\\' Error
29+
'\\' Error
30+
'\\' Error
31+
'\\' Error
32+
'\\' Error
33+
'\\' Error
34+
'\\' Error
35+
'\\' Error
36+
'\\' Error
37+
'\\' Error
38+
'\\' Error
39+
'\\' Error
40+
'\\' Error
41+
'\\' Error
42+
'\\' Error
43+
'\\' Error
44+
'\\' Error
45+
'\\' Error
46+
'\\' Error
47+
'\\' Error
48+
'\\' Error
49+
'\\' Error
50+
'\\' Error
51+
'\\' Error
52+
'\\' Error
53+
'\\' Error
54+
'\\' Error
55+
'\\' Error
56+
'\\' Error
57+
'\\' Error
58+
'\\' Error
59+
'\\' Error
60+
'\\' Error
61+
'\\' Error
62+
'\\' Error
63+
'\\' Error
64+
'\\' Error
65+
'\\' Error
66+
'\\' Error
67+
'\\' Error
68+
'\\' Error
69+
'\\' Error
70+
'\\' Error
71+
'\\' Error
72+
'\\' Error
73+
'\\' Error
74+
'\\' Error
75+
'\\' Error
76+
'\\' Error
77+
'\\' Error
78+
'\\' Error
79+
'\\' Error
80+
'\\' Error
81+
'\\' Error
82+
'\\' Error
83+
'\\' Error
84+
'\\' Error
85+
'\\' Error
86+
'\\' Error
87+
'\\' Error
88+
'\\' Error
89+
'\\' Error
90+
'\\' Error
91+
'\\' Error
92+
'\\' Error
93+
'\\' Error
94+
'\\' Error
95+
'\\' Error
96+
'\\' Error
97+
'\\' Error
98+
'\\' Error
99+
'\\' Error
100+
'\\' Error
101+
'\\' Error
102+
'\\' Error
103+
'\\' Error
104+
'\\' Error
105+
'\\' Error
106+
'\\' Error
107+
'\\' Error
108+
'\\' Error
109+
'\\' Error
110+
'\\' Error
111+
"'" Error
112+
'\n' Text.Whitespace

0 commit comments

Comments
 (0)