Skip to content

Commit

Permalink
add size check of repeat and space
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Dec 17, 2024
1 parent 0817c0f commit 8cff18a
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,10 @@ public static Expression findInSetVarchar(StringLikeLiteral first, StringLikeLit
*/
@ExecFunction(name = "repeat")
public static Expression repeat(StringLikeLiteral first, IntegerLiteral second) {
// when it is too large for fe to make result string, do not folding on fe, limit 1 MB
if ((first.getValue().length() * second.getValue()) > 1000000) {
throw new AnalysisException("repeat too large to fold const by fe");
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < second.getValue(); i++) {
sb.append(first.getValue());
Expand All @@ -642,6 +646,10 @@ public static Expression reverseVarchar(StringLikeLiteral first) {
*/
@ExecFunction(name = "space")
public static Expression space(IntegerLiteral first) {
// when it is too large for fe to make result string, do not folding on fe, limit 1 MB
if (first.getValue() > 1000000) {
throw new AnalysisException("space too large to fold const by fe");
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < first.getValue(); i++) {
sb.append(' ');
Expand Down

0 comments on commit 8cff18a

Please sign in to comment.