mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -804,6 +804,12 @@ NodePointer Demangler::demangleType(StringRef MangledName,
|
|||||||
bool Demangler::parseAndPushNodes() {
|
bool Demangler::parseAndPushNodes() {
|
||||||
const auto textSize = Text.size();
|
const auto textSize = Text.size();
|
||||||
while (Pos < textSize) {
|
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();
|
NodePointer Node = demangleOperator();
|
||||||
if (!Node)
|
if (!Node)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -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()
|
runAllTests()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user