@@ -254,17 +254,6 @@ class Trace extends TTrace {
254
254
}
255
255
}
256
256
257
- /**
258
- * Gets a string corresponding to the trace `t`.
259
- */
260
- string concretise ( Trace t ) {
261
- t = Nil ( ) and result = ""
262
- or
263
- exists ( InputSymbol s1 , InputSymbol s2 , InputSymbol s3 , Trace rest | t = Step ( s1 , s2 , s3 , rest ) |
264
- result = concretise ( rest ) + getAThreewayIntersect ( s1 , s2 , s3 )
265
- )
266
- }
267
-
268
257
/**
269
258
* Holds if there exists a transition from `r` to `q` in the product automaton.
270
259
* Notice that the arguments are flipped, and thus the direction is backwards.
@@ -332,6 +321,39 @@ StateTuple getAnEndTuple(State pivot, State succ) {
332
321
result = MkStateTuple ( pivot , succ , succ )
333
322
}
334
323
324
+ private class RelevantTrace extends Trace {
325
+ RelevantTrace ( ) {
326
+ exists ( State pivot , State succ , StateTuple q |
327
+ isReachableFromStartTuple ( pivot , succ , q , this , _) and
328
+ q = getAnEndTuple ( pivot , succ )
329
+ )
330
+ }
331
+
332
+ private Trace getSuffix ( int i ) {
333
+ i = 0 and
334
+ result = this
335
+ or
336
+ this .getSuffix ( i - 1 ) = Step ( _, _, _, result )
337
+ }
338
+
339
+ private predicate hasTuple ( int i , InputSymbol s1 , InputSymbol s2 , InputSymbol s3 ) {
340
+ this .getSuffix ( i ) = Step ( s1 , s2 , s3 , _)
341
+ }
342
+
343
+ /** Gets a string corresponding to this trace. */
344
+ // the pragma is needed for the case where `getAThreewayIntersect(s1, s2, s3)` has multiple values,
345
+ // not for recursion
346
+ language [ monotonicAggregates]
347
+ string concretise ( ) {
348
+ result =
349
+ concat ( int i , InputSymbol s1 , InputSymbol s2 , InputSymbol s3 |
350
+ this .hasTuple ( i , s1 , s2 , s3 )
351
+ |
352
+ getAThreewayIntersect ( s1 , s2 , s3 ) order by i desc
353
+ )
354
+ }
355
+ }
356
+
335
357
/**
336
358
* Holds if matching repetitions of `pump` can:
337
359
* 1) Transition from `pivot` back to `pivot`.
@@ -345,10 +367,10 @@ StateTuple getAnEndTuple(State pivot, State succ) {
345
367
* available in the `hasReDoSResult` predicate.
346
368
*/
347
369
predicate isPumpable ( State pivot , State succ , string pump ) {
348
- exists ( StateTuple q , Trace t |
370
+ exists ( StateTuple q , RelevantTrace t |
349
371
isReachableFromStartTuple ( pivot , succ , q , t , _) and
350
372
q = getAnEndTuple ( pivot , succ ) and
351
- pump = concretise ( t )
373
+ pump = t . concretise ( )
352
374
)
353
375
}
354
376
0 commit comments