Browse Source

Fix #2180: Restrict the `(uint?)-1` special case to casts to integer types.

This avoids the risk of stack overflows when converting to an unexpected nullable type (such as `Nullable<UnknownType>`).
release/6.2
Daniel Grunwald 5 years ago
parent
commit
a81714f707
  1. 3
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

3
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -502,7 +502,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -502,7 +502,8 @@ namespace ICSharpCode.Decompiler.CSharp
.WithRR(new ByReferenceResolveResult(elementRR, ReferenceKind.Ref));
}
if (this.ResolveResult.IsCompileTimeConstant && this.ResolveResult.ConstantValue != null
&& NullableType.IsNullable(targetType) && !utype.Equals(targetUType))
&& NullableType.IsNullable(targetType) && !utype.Equals(targetUType)
&& targetUType.GetStackType().IsIntegerType())
{
// Casts like `(uint?)-1` are only valid in an explicitly unchecked context, but we
// don't have logic to ensure such a context (usually we emit into an implicitly unchecked context).

Loading…
Cancel
Save