Merge pull request #77346 from mikeash/demangler-nul-terminator

[Demangler] Accept overly short type names if they are NUL terminated
This commit is contained in:
Mike Ash
2024-11-04 20:17:46 -05:00
committed by GitHub
2 changed files with 18 additions and 0 deletions

View File

@@ -804,6 +804,12 @@ NodePointer Demangler::demangleType(StringRef MangledName,
bool Demangler::parseAndPushNodes() {
const auto textSize = Text.size();
while (Pos < textSize) {
// Programs may look up a type by NUL-terminated name with an excessive
// length. Keep them working by returning success if we encounter a NUL in
// the middle of the string where an operator is expected.
if (peekChar() == '\0')
return true;
NodePointer Node = demangleOperator();
if (!Node)
return false;

View File

@@ -566,5 +566,17 @@ if #available(SwiftStdlib 6.0, *) {
}
}
if #available(SwiftStdlib 6.1, *) {
DemangleToMetadataTests.test("NUL-terminated name, excessive length value") {
let t = _getTypeByMangledNameInContext("4main1SV", 256,
genericContext: nil,
genericArguments: nil)
expectNotNil(t)
if let t {
expectEqual(type(of: S()), t)
}
}
}
runAllTests()