Skip to content

Commit 99e0c1d

Browse files
authored
Merge pull request swiftlang#20912 from dnadoba/master
Refuse to import C arrays that are longer than 4096
2 parents e62795e + 9e19dc9 commit 99e0c1d

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,17 @@ namespace {
480480
Bridgeability::None);
481481
if (!elementType)
482482
return Type();
483+
484+
auto size = type->getSize().getZExtValue();
485+
// An array of size N is imported as an N-element tuple which
486+
// takes very long to compile. We chose 4096 as the upper limit because
487+
// we don't want to break arrays of size PATH_MAX.
488+
if (size > 4096)
489+
return Type();
483490

484491
TupleTypeElt elt(elementType);
485492
SmallVector<TupleTypeElt, 8> elts;
486-
for (size_t i = 0, size = type->getSize().getZExtValue(); i < size; ++i)
493+
for (size_t i = 0; i < size; ++i)
487494
elts.push_back(elt);
488495

489496
return TupleType::get(elts, elementType->getASTContext());

0 commit comments

Comments
 (0)