Browse Source

Fix #3367: Add extra validation to TransformDecimalCtorToConstant to prevent crashes with obfuscated assemblies.

pull/3366/merge
Siegfried Pammer 4 months ago
parent
commit
b9f50901a4
  1. 9
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs

9
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs

@ -260,6 +260,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -260,6 +260,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return (byte)(x & 0x10);
}
public decimal Issue3367()
{
#if CS70
return new decimal(0, 0, 0, isNegative: false, 29);
#else
return new decimal(0, 0, 0, false, 29);
#endif
}
private void ExpectUInt64(ulong _)
{

2
ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs

@ -213,7 +213,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -213,7 +213,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
int lo, mid, hi, isNegative, scale;
if (args[0].MatchLdcI4(out lo) && args[1].MatchLdcI4(out mid) &&
args[2].MatchLdcI4(out hi) && args[3].MatchLdcI4(out isNegative) &&
args[4].MatchLdcI4(out scale))
args[4].MatchLdcI4(out scale) && scale <= 28)
{
result = new LdcDecimal(new decimal(lo, mid, hi, isNegative != 0, (byte)scale));
return true;

Loading…
Cancel
Save