Skip to content

Commit b9f5090

Browse files
Fix #3367: Add extra validation to TransformDecimalCtorToConstant to prevent crashes with obfuscated assemblies.
1 parent 507da70 commit b9f5090

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ public byte Issue2166b(int x)
260260
return (byte)(x & 0x10);
261261
}
262262

263+
public decimal Issue3367()
264+
{
265+
#if CS70
266+
return new decimal(0, 0, 0, isNegative: false, 29);
267+
#else
268+
return new decimal(0, 0, 0, false, 29);
269+
#endif
270+
}
271+
263272
private void ExpectUInt64(ulong _)
264273
{
265274

ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ bool TransformDecimalCtorToConstant(NewObj inst, out LdcDecimal result)
213213
int lo, mid, hi, isNegative, scale;
214214
if (args[0].MatchLdcI4(out lo) && args[1].MatchLdcI4(out mid) &&
215215
args[2].MatchLdcI4(out hi) && args[3].MatchLdcI4(out isNegative) &&
216-
args[4].MatchLdcI4(out scale))
216+
args[4].MatchLdcI4(out scale) && scale <= 28)
217217
{
218218
result = new LdcDecimal(new decimal(lo, mid, hi, isNegative != 0, (byte)scale));
219219
return true;

0 commit comments

Comments
 (0)