@@ -460,10 +460,26 @@ private CallCfgNode getSuperCall() {
460
460
)
461
461
}
462
462
463
+ /**
464
+ * Holds if the file `f` should be ignored when computing the call-graph.
465
+ *
466
+ * We currently see a performance problem when analyzing the `sympy` PyPI package,
467
+ * which can be part of the database when dependencies are installed and extracted.
468
+ * From what we can understand, SymPy is using Python in a exotic way, so the fact that
469
+ * our analysis currently does not handle this project has nothing to say about our
470
+ * ability to handle normal Python code. Furthermore, SymPy does not look to be relevant
471
+ * in a security context, so we should not loose out on any security results by doing
472
+ * this.
473
+ */
474
+ private predicate ignoreForCallGraph ( File f ) {
475
+ f .getAbsolutePath ( ) .matches ( "%/site-packages/sympy/%" )
476
+ }
477
+
463
478
/**
464
479
* Gets a reference to the function `func`.
465
480
*/
466
481
private TypeTrackingNode functionTracker ( TypeTracker t , Function func ) {
482
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
467
483
t .start ( ) and
468
484
(
469
485
result .asExpr ( ) = func .getDefinition ( )
@@ -473,6 +489,7 @@ private TypeTrackingNode functionTracker(TypeTracker t, Function func) {
473
489
result .asExpr ( ) = func .getDefinition ( ) .( FunctionExpr ) .getADecoratorCall ( )
474
490
)
475
491
or
492
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
476
493
exists ( TypeTracker t2 | result = functionTracker ( t2 , func ) .track ( t2 , t ) )
477
494
}
478
495
@@ -485,6 +502,7 @@ Node functionTracker(Function func) { functionTracker(TypeTracker::end(), func).
485
502
* Gets a reference to the class `cls`.
486
503
*/
487
504
private TypeTrackingNode classTracker ( TypeTracker t , Class cls ) {
505
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
488
506
t .start ( ) and
489
507
(
490
508
result .asExpr ( ) = cls .getParent ( )
@@ -498,6 +516,7 @@ private TypeTrackingNode classTracker(TypeTracker t, Class cls) {
498
516
result .( CallCfgNode ) .getArg ( 0 ) = classInstanceTracker ( cls )
499
517
)
500
518
or
519
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
501
520
exists ( TypeTracker t2 | result = classTracker ( t2 , cls ) .track ( t2 , t ) ) and
502
521
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
503
522
}
@@ -511,16 +530,19 @@ Node classTracker(Class cls) { classTracker(TypeTracker::end(), cls).flowsTo(res
511
530
* Gets a reference to an instance of the class `cls`.
512
531
*/
513
532
private TypeTrackingNode classInstanceTracker ( TypeTracker t , Class cls ) {
533
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
514
534
t .start ( ) and
515
535
resolveClassCall ( result .( CallCfgNode ) .asCfgNode ( ) , cls )
516
536
or
517
537
// result of `super().__new__` as used in a `__new__` method implementation
538
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
518
539
t .start ( ) and
519
540
exists ( Class classUsedInSuper |
520
541
fromSuperNewCall ( result .( CallCfgNode ) .asCfgNode ( ) , classUsedInSuper , _, _) and
521
542
classUsedInSuper = getADirectSuperclass * ( cls )
522
543
)
523
544
or
545
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
524
546
exists ( TypeTracker t2 | result = classInstanceTracker ( t2 , cls ) .track ( t2 , t ) ) and
525
547
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
526
548
}
@@ -537,6 +559,7 @@ Node classInstanceTracker(Class cls) {
537
559
* The method cannot be a `staticmethod` or `classmethod`.
538
560
*/
539
561
private TypeTrackingNode selfTracker ( TypeTracker t , Class classWithMethod ) {
562
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
540
563
t .start ( ) and
541
564
exists ( Function func |
542
565
func = classWithMethod .getAMethod ( ) and
@@ -546,6 +569,7 @@ private TypeTrackingNode selfTracker(TypeTracker t, Class classWithMethod) {
546
569
result .asExpr ( ) = func .getArg ( 0 )
547
570
)
548
571
or
572
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
549
573
exists ( TypeTracker t2 | result = selfTracker ( t2 , classWithMethod ) .track ( t2 , t ) ) and
550
574
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
551
575
}
@@ -564,6 +588,7 @@ Node selfTracker(Class classWithMethod) {
564
588
* from a normal method.
565
589
*/
566
590
private TypeTrackingNode clsArgumentTracker ( TypeTracker t , Class classWithMethod ) {
591
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
567
592
t .start ( ) and
568
593
(
569
594
exists ( Function func |
@@ -578,6 +603,7 @@ private TypeTrackingNode clsArgumentTracker(TypeTracker t, Class classWithMethod
578
603
result .( CallCfgNode ) .getArg ( 0 ) = selfTracker ( classWithMethod )
579
604
)
580
605
or
606
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
581
607
exists ( TypeTracker t2 | result = clsArgumentTracker ( t2 , classWithMethod ) .track ( t2 , t ) ) and
582
608
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
583
609
}
@@ -596,6 +622,7 @@ Node clsArgumentTracker(Class classWithMethod) {
596
622
* call happened in the method `func` (either a method or a classmethod).
597
623
*/
598
624
private TypeTrackingNode superCallNoArgumentTracker ( TypeTracker t , Function func ) {
625
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
599
626
t .start ( ) and
600
627
not isStaticmethod ( func ) and
601
628
exists ( CallCfgNode call | result = call |
@@ -604,6 +631,7 @@ private TypeTrackingNode superCallNoArgumentTracker(TypeTracker t, Function func
604
631
call .getScope ( ) = func
605
632
)
606
633
or
634
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
607
635
exists ( TypeTracker t2 | result = superCallNoArgumentTracker ( t2 , func ) .track ( t2 , t ) ) and
608
636
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
609
637
}
@@ -621,13 +649,15 @@ Node superCallNoArgumentTracker(Function func) {
621
649
* first is a reference to the class `cls`, and the second argument is `obj`.
622
650
*/
623
651
private TypeTrackingNode superCallTwoArgumentTracker ( TypeTracker t , Class cls , Node obj ) {
652
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
624
653
t .start ( ) and
625
654
exists ( CallCfgNode call | result = call |
626
655
call = getSuperCall ( ) and
627
656
call .getArg ( 0 ) = classTracker ( cls ) and
628
657
call .getArg ( 1 ) = obj
629
658
)
630
659
or
660
+ not ignoreForCallGraph ( result .getLocation ( ) .getFile ( ) ) and
631
661
exists ( TypeTracker t2 | result = superCallTwoArgumentTracker ( t2 , cls , obj ) .track ( t2 , t ) ) and
632
662
not result .( ParameterNodeImpl ) .isParameterOf ( _, any ( ParameterPosition pp | pp .isSelf ( ) ) )
633
663
}
0 commit comments