Commit ec19a26
authored
Root cause: Three unbounded loops in expression parsing could hang
indefinitely on malformed input or pathological code structures:
1. parse_expression_with_precedence main loop
2. collect_index_arguments argument parsing loop
3. parse_simple_array_elements element parsing loop
4. parse_modern_array_literal element parsing loop
5. Type specifier parenthesis depth matching loop
Changes:
- Added MAX_ITERATIONS limit to main expression parser (100000)
- Added MAX_ARGUMENTS limit to argument collector (10000)
- Added element count limits to array literal parsers (100000)
- Added MAX_PAREN_DEPTH limit to type specifier parsing (1000)
These limits prevent infinite loops while supporting real-world code
that uses complex expressions with many nested calls or large array
literals.
Testing:
- Added test_parser_iteration_limits.f90 regression test
- Verified all existing tests pass (505/505 non-xfail)
- Tested with maxloc/minloc intrinsics with dim and mask
- Tested with functions having 20+ arguments
- Tested with 50-element array literals
ISO compliance: Fortran standard places no hard limits on nesting
depth or argument counts. These limits are implementation-defined
(ISO/IEC 1539-1:2018 Section 2.3.4) and exceed practical usage.
1 parent cee30d5 commit ec19a26
File tree
3 files changed
+134
-14
lines changed- src/parser/expressions
- test
3 files changed
+134
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
284 | 290 | | |
285 | 291 | | |
286 | 292 | | |
| |||
301 | 307 | | |
302 | 308 | | |
303 | 309 | | |
304 | | - | |
| 310 | + | |
305 | 311 | | |
306 | 312 | | |
307 | 313 | | |
| |||
787 | 793 | | |
788 | 794 | | |
789 | 795 | | |
| 796 | + | |
| 797 | + | |
790 | 798 | | |
791 | 799 | | |
792 | 800 | | |
| |||
799 | 807 | | |
800 | 808 | | |
801 | 809 | | |
| 810 | + | |
802 | 811 | | |
803 | | - | |
| 812 | + | |
| 813 | + | |
804 | 814 | | |
805 | 815 | | |
806 | 816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
443 | 443 | | |
444 | 444 | | |
445 | 445 | | |
| 446 | + | |
| 447 | + | |
446 | 448 | | |
447 | 449 | | |
448 | 450 | | |
449 | 451 | | |
450 | 452 | | |
451 | 453 | | |
452 | 454 | | |
| 455 | + | |
453 | 456 | | |
454 | | - | |
| 457 | + | |
| 458 | + | |
455 | 459 | | |
456 | 460 | | |
457 | 461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
0 commit comments