From b9f50901a498fe8f2c0a93f412ece19267076c31 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 13 Jan 2025 19:35:15 +0100 Subject: [PATCH] Fix #3367: Add extra validation to TransformDecimalCtorToConstant to prevent crashes with obfuscated assemblies. --- .../TestCases/Pretty/ConstantsTests.cs | 9 +++++++++ .../IL/Transforms/EarlyExpressionTransforms.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs index 7bada42063..851813fb53 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstantsTests.cs @@ -260,6 +260,15 @@ public byte Issue2166b(int x) 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 _) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs index 3d99d04009..2316732e90 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/EarlyExpressionTransforms.cs @@ -213,7 +213,7 @@ bool TransformDecimalCtorToConstant(NewObj inst, out LdcDecimal result) 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;