Commit 4c46a60
fix(detector): eliminate regex backtracking in Liquibase YAML patterns (#61)
SonarCloud S5998 (reliability: stack overflow on large input) + S5852
(security hotspot: ReDoS) both flagged the reluctant-outer quantifier
`(?:\s++[^\n]*+\n)*?` in LQ_CREATE_TABLE_YAML and LQ_ADD_FK_YAML. The
engine was free to backtrack through the reluctant `*?`.
Rewrite with negative-lookahead + possessive `*+`: intermediate lines
that would otherwise match the target key (tableName / baseTableName /
referencedTableName) are excluded up front, so the outer match
terminates deterministically exactly where the reluctant version did.
No semantic change for valid Liquibase YAML.
Adds a regression test exercising a 500-line pathological createTable
block — completes in <1s on the rewritten patterns; the pre-fix
reluctant walk would have scaled quadratically.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent bfab2e7 commit 4c46a60
2 files changed
Lines changed: 47 additions & 3 deletions
File tree
- src
- main/java/io/github/randomcodespace/iq/detector/sql
- test/java/io/github/randomcodespace/iq/detector/sql
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
145 | 149 | | |
146 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
147 | 153 | | |
148 | 154 | | |
149 | | - | |
150 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
151 | 159 | | |
152 | 160 | | |
153 | 161 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
212 | 248 | | |
213 | 249 | | |
214 | 250 | | |
| |||
0 commit comments