[FileCheck] Limit quadratic partial-match search behavior (#147833)

This commit is contained in:
Jon Roelofs 2025-07-23 08:40:11 -07:00 committed by GitHub
parent f4d0d124cb
commit a7867fcd94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -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')

File diff suppressed because one or more lines are too long