Skip to content

Commit 794165a

Browse files
authored
Merge pull request #77346 from mikeash/demangler-nul-terminator
[Demangler] Accept overly short type names if they are NUL terminated
2 parents 38dc77b + 4a5dc2a commit 794165a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Demangling/Demangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,12 @@ NodePointer Demangler::demangleType(StringRef MangledName,
804804
bool Demangler::parseAndPushNodes() {
805805
const auto textSize = Text.size();
806806
while (Pos < textSize) {
807+
// Programs may look up a type by NUL-terminated name with an excessive
808+
// length. Keep them working by returning success if we encounter a NUL in
809+
// the middle of the string where an operator is expected.
810+
if (peekChar() == '\0')
811+
return true;
812+
807813
NodePointer Node = demangleOperator();
808814
if (!Node)
809815
return false;

test/Runtime/demangleToMetadata.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,17 @@ if #available(SwiftStdlib 6.0, *) {
566566
}
567567
}
568568

569+
if #available(SwiftStdlib 6.1, *) {
570+
DemangleToMetadataTests.test("NUL-terminated name, excessive length value") {
571+
let t = _getTypeByMangledNameInContext("4main1SV", 256,
572+
genericContext: nil,
573+
genericArguments: nil)
574+
expectNotNil(t)
575+
if let t {
576+
expectEqual(type(of: S()), t)
577+
}
578+
}
579+
}
580+
569581
runAllTests()
570582

0 commit comments

Comments
 (0)