Skip to content

Commit a7867fc

Browse files
authored
[FileCheck] Limit quadratic partial-match search behavior (#147833)
1 parent f4d0d12 commit a7867fc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ void Pattern::printFuzzyMatch(const SourceMgr &SM, StringRef Buffer,
13601360
size_t Best = StringRef::npos;
13611361
double BestQuality = 0;
13621362

1363+
// Arbitrarily limit quadratic search behavior stemming from long CHECK lines.
1364+
if (size_t(4096) * size_t(2048) <
1365+
std::min(size_t(4096), Buffer.size()) *
1366+
std::max(FixedStr.size(), RegExStr.size()))
1367+
return;
1368+
13631369
// Use an arbitrary 4k limit on how far we will search.
13641370
for (size_t i = 0, e = std::min(size_t(4096), Buffer.size()); i != e; ++i) {
13651371
if (Buffer[i] == '\n')

llvm/test/FileCheck/long-check.txt

Lines changed: 9 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)