Skip to content

Commit 219a622

Browse files
authored
Merge pull request #19926 from hvitved/ruby/restrict-string-component-length
Ruby: Do not compute `StringlikeLiteralImpl.getStringValue` for large strings
2 parents a791640 + 41a403c commit 219a622

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,27 @@ 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
590+
// if all interpolations have a known string value, we will get a result, unless the
591+
// combined length exceeds 10,000 characters
584592
language[monotonicAggregates]
585593
final string getStringValue() {
594+
not exists(this.getComponentImpl(_)) and
595+
result = ""
596+
or
586597
result =
587-
concat(StringComponentImpl c, int i | c = this.getComponentImpl(i) | c.getValue() order by i)
598+
strictconcat(StringComponentImpl c, int i |
599+
c = this.getComponentImplRestricted(i)
600+
|
601+
c.getValue() order by i
602+
)
588603
}
589604
}
590605

0 commit comments

Comments
 (0)