Skip to content

Commit 5937d3b

Browse files
committed
swift-demangle: fix a crash for invalid input
When fed with invalid input, the swift-demangle tool crashed. rdar://148754959
1 parent 8802395 commit 5937d3b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Demangling/NodePrinter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,8 @@ void NodePrinter::printFunctionSigSpecializationParams(NodePointer Node,
12651265
break;
12661266
case FunctionSigSpecializationParamKind::ConstantPropFunction:
12671267
case FunctionSigSpecializationParamKind::ConstantPropGlobal: {
1268+
if (Idx + 2 > End)
1269+
return;
12681270
Printer << "[";
12691271
print(Node->getChild(Idx++), depth + 1);
12701272
Printer << " : ";
@@ -1280,13 +1282,17 @@ void NodePrinter::printFunctionSigSpecializationParams(NodePointer Node,
12801282
}
12811283
case FunctionSigSpecializationParamKind::ConstantPropInteger:
12821284
case FunctionSigSpecializationParamKind::ConstantPropFloat:
1285+
if (Idx + 2 > End)
1286+
return;
12831287
Printer << "[";
12841288
print(Node->getChild(Idx++), depth + 1);
12851289
Printer << " : ";
12861290
print(Node->getChild(Idx++), depth + 1);
12871291
Printer << "]";
12881292
break;
12891293
case FunctionSigSpecializationParamKind::ConstantPropString:
1294+
if (Idx + 3 > End)
1295+
return;
12901296
Printer << "[";
12911297
print(Node->getChild(Idx++), depth + 1);
12921298
Printer << " : ";
@@ -1297,6 +1303,8 @@ void NodePrinter::printFunctionSigSpecializationParams(NodePointer Node,
12971303
Printer << "]";
12981304
break;
12991305
case FunctionSigSpecializationParamKind::ConstantPropKeyPath:
1306+
if (Idx + 4 > End)
1307+
return;
13001308
Printer << "[";
13011309
print(Node->getChild(Idx++), depth + 1);
13021310
Printer << " : ";
@@ -1308,6 +1316,8 @@ void NodePrinter::printFunctionSigSpecializationParams(NodePointer Node,
13081316
Printer << ">]";
13091317
break;
13101318
case FunctionSigSpecializationParamKind::ClosureProp:
1319+
if (Idx + 2 > End)
1320+
return;
13111321
Printer << "[";
13121322
print(Node->getChild(Idx++), depth + 1);
13131323
Printer << " : ";

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ $s4test3fooyyS2f_SfYkztYjrXEF ---> test.foo(@differentiable(reverse) (Swift.Floa
420420
$s4test3fooyyS2f_SfYkntYjrXEF ---> test.foo(@differentiable(reverse) (Swift.Float, __owned @noDerivative Swift.Float) -> Swift.Float) -> ()
421421
$s4test3fooyyS2f_SfYktYjrXEF ---> test.foo(@differentiable(reverse) (Swift.Float, @noDerivative Swift.Float) -> Swift.Float) -> ()
422422
$s4test3fooyyS2f_SfYktYaYbYjrXEF ---> test.foo(@differentiable(reverse) @Sendable (Swift.Float, @noDerivative Swift.Float) async -> Swift.Float) -> ()
423+
$SSSTf4pd44444_pf ---> function signature specialization <Arg[0] = [Constant Propagated Float : 44444], Return = > of Swift.String
423424
$sScA ---> Swift.Actor
424425
$sScGySiG ---> Swift.TaskGroup<Swift.Int>
425426
$s4test10returnsOptyxycSgxyScMYccSglF ---> test.returnsOpt<A>((@Swift.MainActor () -> A)?) -> (() -> A)?

0 commit comments

Comments
 (0)