aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorJon Roelofs <jonathan_roelofs@apple.com>2025-07-23 08:40:11 -0700
committerGitHub <noreply@github.com>2025-07-23 08:40:11 -0700
commita7867fcd94555fb056bcaac66de45d4635da99bf (patch)
tree806e30d427e3f416bc1a308bc0b57edbf5286330 /llvm/lib/FileCheck/FileCheck.cpp
parentf4d0d124cb5e2157d32aef69d9ab52abcea7fb23 (diff)
downloadllvm-a7867fcd94555fb056bcaac66de45d4635da99bf.zip
llvm-a7867fcd94555fb056bcaac66de45d4635da99bf.tar.gz
llvm-a7867fcd94555fb056bcaac66de45d4635da99bf.tar.bz2
[FileCheck] Limit quadratic partial-match search behavior (#147833)
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index b79f6ec..ce35a5b 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1360,6 +1360,12 @@ void Pattern::printFuzzyMatch(const SourceMgr &SM, StringRef Buffer,
size_t Best = StringRef::npos;
double BestQuality = 0;
+ // Arbitrarily limit quadratic search behavior stemming from long CHECK lines.
+ if (size_t(4096) * size_t(2048) <
+ std::min(size_t(4096), Buffer.size()) *
+ std::max(FixedStr.size(), RegExStr.size()))
+ return;
+
// Use an arbitrary 4k limit on how far we will search.
for (size_t i = 0, e = std::min(size_t(4096), Buffer.size()); i != e; ++i) {
if (Buffer[i] == '\n')