Skip to content

Commit 550f14c

Browse files
committed
Ruby: Do not compute StringlikeLiteralImpl.getStringValue for large strings
1 parent 632cde6 commit 550f14c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Literal.qll

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,26 @@ abstract class StringlikeLiteralImpl extends Expr, TStringlikeLiteral {
579579
)
580580
}
581581

582+
pragma[nomagic]
583+
private StringComponentImpl getComponentImplRestricted(int n) {
584+
result = this.getComponentImpl(n) and
585+
strictsum(int length, int i | length = this.getComponentImpl(i).getValue().length() | length) <
586+
10000
587+
}
588+
582589
// 0 components results in the empty string
583-
// if all interpolations have a known string value, we will get a result
584-
language[monotonicAggregates]
590+
// if all interpolations have a known string value, we will get a result, unless the
591+
// combined length exceeds 10,000 characters
585592
final string getStringValue() {
593+
not exists(this.getComponentImpl(_)) and
594+
result = ""
595+
or
586596
result =
587-
concat(StringComponentImpl c, int i | c = this.getComponentImpl(i) | c.getValue() order by i)
597+
strictconcat(StringComponentImpl c, int i |
598+
c = this.getComponentImplRestricted(i)
599+
|
600+
c.getValue() order by i
601+
)
588602
}
589603
}
590604

0 commit comments

Comments
 (0)