forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit538b3b8
committed
Improve memory-usage accounting in regular-expression compiler.
This code previously counted the number of NFA states it created, andcomplained if a limit was exceeded, so as to prevent bizarre regex patternsfrom consuming unreasonable time or memory. That's fine as far as it went,but the code paid no attention to how many arcs linked those states. Sinceregexes can be contrived that have O(N) states but will need O(N^2) arcsafter fixempties() processing, it was still possible to blow out memory,and take a long time doing it too. To fix, modify the bookkeeping to countspace used by both states and arcs.I did not bother with including the "color map" in the accounting; itcan only grow to a few megabytes, which is not a lot in comparison towhat we're allowing for states+arcs (about 150MB on 64-bit machinesor half that on 32-bit machines).Looking at some of the larger real-world regexes captured in the Tclregression test suite suggests that the most that is likely to be neededfor regexes found in the wild is under 10MB, so I believe that the currentlimit has enough headroom to make it okay to keep it as a hard-wired limit.In connection with this, redefine REG_ETOOBIG as meaning "regularexpression is too complex"; the previous wording of "nfa has too manystates" was already somewhat inapropos because of the error code's usefor stack depth overrun, and it was not very user-friendly either.Back-patch to all supported branches.1 parent6a71536 commit538b3b8
File tree
5 files changed
+27
-69
lines changed- src
- backend/regex
- include/regex
5 files changed
+27
-69
lines changedLines changed: 14 additions & 61 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 |
| - | |
67 | 66 |
| |
68 | 67 |
| |
69 | 68 |
| |
| |||
92 | 91 |
| |
93 | 92 |
| |
94 | 93 |
| |
95 |
| - | |
96 |
| - | |
97 |
| - | |
98 |
| - | |
99 |
| - | |
100 |
| - | |
101 |
| - | |
102 |
| - | |
103 |
| - | |
104 |
| - | |
105 |
| - | |
106 |
| - | |
107 |
| - | |
108 |
| - | |
109 |
| - | |
110 |
| - | |
111 |
| - | |
112 |
| - | |
113 |
| - | |
114 |
| - | |
115 |
| - | |
116 |
| - | |
117 |
| - | |
118 |
| - | |
119 |
| - | |
120 |
| - | |
121 |
| - | |
122 |
| - | |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 |
| - | |
128 |
| - | |
129 |
| - | |
130 |
| - | |
131 |
| - | |
132 |
| - | |
133 |
| - | |
134 |
| - | |
135 |
| - | |
136 |
| - | |
137 |
| - | |
138 |
| - | |
139 |
| - | |
140 |
| - | |
141 |
| - | |
142 |
| - | |
143 |
| - | |
144 |
| - | |
145 |
| - | |
146 | 94 |
| |
147 | 95 |
| |
148 | 96 |
| |
| |||
188 | 136 |
| |
189 | 137 |
| |
190 | 138 |
| |
191 |
| - | |
192 |
| - | |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 |
| - | |
197 | 139 |
| |
198 | 140 |
| |
199 | 141 |
| |
200 | 142 |
| |
201 | 143 |
| |
202 | 144 |
| |
203 | 145 |
| |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
204 | 151 |
| |
205 | 152 |
| |
206 | 153 |
| |
207 | 154 |
| |
208 | 155 |
| |
209 | 156 |
| |
| 157 | + | |
210 | 158 |
| |
211 | 159 |
| |
212 | 160 |
| |
| |||
230 | 178 |
| |
231 | 179 |
| |
232 | 180 |
| |
233 |
| - | |
234 |
| - | |
235 | 181 |
| |
236 | 182 |
| |
237 | 183 |
| |
| |||
294 | 240 |
| |
295 | 241 |
| |
296 | 242 |
| |
297 |
| - | |
298 | 243 |
| |
299 | 244 |
| |
300 | 245 |
| |
| |||
312 | 257 |
| |
313 | 258 |
| |
314 | 259 |
| |
| 260 | + | |
315 | 261 |
| |
316 | 262 |
| |
317 | 263 |
| |
318 | 264 |
| |
319 | 265 |
| |
| 266 | + | |
320 | 267 |
| |
321 | 268 |
| |
322 | 269 |
| |
| |||
437 | 384 |
| |
438 | 385 |
| |
439 | 386 |
| |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
440 | 392 |
| |
441 | 393 |
| |
442 | 394 |
| |
443 | 395 |
| |
444 | 396 |
| |
445 | 397 |
| |
| 398 | + | |
446 | 399 |
| |
447 | 400 |
| |
448 | 401 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
248 | 248 |
| |
249 | 249 |
| |
250 | 250 |
| |
| 251 | + | |
251 | 252 |
| |
252 | 253 |
| |
253 | 254 |
| |
| |||
363 | 364 |
| |
364 | 365 |
| |
365 | 366 |
| |
| 367 | + | |
366 | 368 |
| |
367 | 369 |
| |
368 | 370 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
75 | 75 |
| |
76 | 76 |
| |
77 | 77 |
| |
78 |
| - | |
| 78 | + | |
79 | 79 |
| |
80 | 80 |
| |
81 | 81 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
152 | 152 |
| |
153 | 153 |
| |
154 | 154 |
| |
155 |
| - | |
| 155 | + | |
156 | 156 |
| |
157 | 157 |
| |
158 | 158 |
| |
|
Lines changed: 9 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
334 | 334 |
| |
335 | 335 |
| |
336 | 336 |
| |
337 |
| - | |
338 |
| - | |
339 |
| - | |
340 | 337 |
| |
341 | 338 |
| |
342 | 339 |
| |
| |||
384 | 381 |
| |
385 | 382 |
| |
386 | 383 |
| |
387 |
| - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
388 | 390 |
| |
389 |
| - | |
390 |
| - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
391 | 394 |
| |
392 | 395 |
| |
393 | 396 |
| |
|
0 commit comments
Comments
(0)