Skip to content

Commit b2e070f

Browse files
authored
Merge pull request #15273 from eeckstein/fix-demangler-4.1
demangler: fix crashes for malformed symbols.
2 parents ec821ef + 68286ba commit b2e070f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,10 +1952,10 @@ NodePointer Demangler::demangleSubscript() {
19521952
NodePointer Context = popContext();
19531953

19541954
NodePointer Subscript = createNode(Node::Kind::Subscript);
1955-
Subscript->addChild(Context, *this);
1956-
Subscript->addChild(Type, *this);
1955+
Subscript = addChild(Subscript, Context);
1956+
Subscript = addChild(Subscript, Type);
19571957
if (PrivateName)
1958-
Subscript->addChild(PrivateName, *this);
1958+
Subscript = addChild(Subscript, PrivateName);
19591959

19601960
return demangleAccessor(Subscript);
19611961
}

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ class NodePrinter {
541541
}
542542

543543
void printFunctionType(NodePointer node) {
544-
assert(node->getNumChildren() == 2 || node->getNumChildren() == 3);
544+
if (node->getNumChildren() != 2 && node->getNumChildren() != 3)
545+
return;
545546
unsigned startIndex = 0;
546547
bool throws = false;
547548
if (node->getNumChildren() == 3) {
@@ -1896,9 +1897,10 @@ printEntity(NodePointer Entity, bool asPrefixContext, TypePrinting TypePr,
18961897
}
18971898
if (TypePr != TypePrinting::NoType) {
18981899
NodePointer type = Entity->getChild(1);
1899-
if (type->getKind() != Node::Kind::Type)
1900+
if (type->getKind() != Node::Kind::Type && Entity->getNumChildren() >= 3)
19001901
type = Entity->getChild(2);
1901-
assert(type->getKind() == Node::Kind::Type);
1902+
if (type->getKind() != Node::Kind::Type)
1903+
return nullptr;
19021904
type = type->getChild(0);
19031905
if (TypePr == TypePrinting::FunctionStyle) {
19041906
// We expect to see a function type here, but if we don't, use the colon.

test/Demangle/Inputs/manglings.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,10 @@ _T0So5GizmoC11doSomethingSQyypGSQySaySSGGFToTembnn_ ---> outlined bridged method
278278
_T0So5GizmoC12modifyStringSQySSGAD_Si10withNumberSQyypG0D6FoobartFToTembnnnb_ ---> outlined bridged method (mbnnnb) of @objc __ObjC.Gizmo.modifyString(Swift.String!, withNumber: Swift.Int, withFoobar: Any!) -> Swift.String!
279279
_T04test1SVyxGAA1RA2A1ZRzAA1Y2ZZRpzl1A_AhaGPWT ---> {C} associated type witness table accessor for A.ZZ : test.Y in <A where A: test.Z, A.ZZ: test.Y> test.S<A> : test.R in test
280280
_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfC ---> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69).init() -> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69)
281+
_$S10NibbleSort0A10CollectionVys6UInt64VAEcis ---> _$S10NibbleSort0A10CollectionVys6UInt64VAEcis
282+
_T0D ---> _T0D
283+
_T0s3SetVyxGs10CollectiotySivm ---> _T0s3SetVyxGs10CollectiotySivm
284+
_T0s18ReversedCollectionVyxGs04LazyB8ProtocolfC ---> _T0s18ReversedCollectionVyxGs04LazyB8ProtocolfC
285+
_T0iW ---> _T0iW
286+
_T0s5print_9separator10terminatoryypfC ---> _T0s5print_9separator10terminatoryypfC
281287

0 commit comments

Comments
 (0)