From ede17f98c9dd9396f9b3f4079af166a784e4baac Mon Sep 17 00:00:00 2001 From: Jb Evain Date: Fri, 2 Jul 2021 14:08:04 -0700 Subject: [PATCH] Fix handling of empty string constants (#776) --- Mono.Cecil/AssemblyReader.cs | 4 +++- Test/Mono.Cecil.Tests/PortablePdbTests.cs | 17 +++++++++++++++++ Test/Resources/assemblies/empty-str-const.exe | Bin 0 -> 4096 bytes Test/Resources/assemblies/empty-str-const.pdb | Bin 0 -> 2668 bytes 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 Test/Resources/assemblies/empty-str-const.exe create mode 100644 Test/Resources/assemblies/empty-str-const.pdb diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 5cd3d1784..b66c1622e 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -3005,7 +3005,9 @@ ConstantDebugInformation ReadLocalConstant (uint rid) object value; if (type.etype == ElementType.String) { - if (signature.CanReadMore () && signature.buffer [signature.position] != 0xff) { + if (!signature.CanReadMore ()) + value = ""; + else if (signature.buffer [signature.position] != 0xff) { var bytes = signature.ReadBytes ((int) (signature.sig_length - (signature.position - signature.start))); value = Encoding.Unicode.GetString (bytes, 0, bytes.Length); } else diff --git a/Test/Mono.Cecil.Tests/PortablePdbTests.cs b/Test/Mono.Cecil.Tests/PortablePdbTests.cs index 43b8cfed2..d9786cb37 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -474,6 +474,23 @@ public void GenericInstConstantRecord () } } + [Test] + public void EmptyStringLocalConstant () + { + TestModule ("empty-str-const.exe", module => { + var type = module.GetType ("$"); + var method = type.GetMethod ("
$"); + var symbol = method.DebugInformation; + + Assert.IsNotNull (symbol); + Assert.AreEqual (1, symbol.Scope.Constants.Count); + + var a = symbol.Scope.Constants [0]; + Assert.AreEqual ("value", a.Name); + Assert.AreEqual ("", a.Value); + }, symbolReaderProvider: typeof (PortablePdbReaderProvider), symbolWriterProvider: typeof (PortablePdbWriterProvider)); + } + [Test] public void SourceLink () { diff --git a/Test/Resources/assemblies/empty-str-const.exe b/Test/Resources/assemblies/empty-str-const.exe new file mode 100644 index 0000000000000000000000000000000000000000..6cc51287f0b2a6fe4e888dd32a6d7867253e9b5a GIT binary patch literal 4096 zcmeHJO>9(E6h3b{Ez@Ev6(mCaxlGHCXkQ1~8X*0d{!waLI_Z>Zl!U%{b31+de#Up- zlo?}87rG#BaAP#V#JF&!2_^=Jgt&mE#Feg0WNFldg+z@D>v!*a(`gGqSgM@%o_o%@ z=bpcN-#s(+(pjn_qBzFN3ehFZ64DCa9W7(I<*6@Q=!?edyDn*y*LTe>T7ngQuizUF zGY!}E0+!>#lpBjsrcng%NUSLsH61TL|fEdK(~?dT-I7Jv2=hb_K~`=j zI<#@^ZaiBJU1=r2A6uiZ2fQ4BpR5PMn#whb8=L}0G_U)@H^Hgc(jeB<1e}62qSt+H zdr*|I(maN=)q=4G(nP~+SViuYbp^=SVpLBygN-^O4LpYQc3-eH6;p1px77zKK0^DD zV$+`eaGrgBSW}k6IG1|#l-`}{K5$sNfN$Ug_O!oA6kzU~ZFB)LqMZuMESI${%EAs{jWSFwyo>YcP*RQR zwMM!Ex)r#Ab^tfg(~3S!&%&Ngn`uArR_X?BqZt~Zc6u3E$CqJh9ke3!wU@UIni2G6 z!q0J_gZicn%f&q52Hgk2dHIsf2gnho=i63}X8lUW@CBz4&na3q_s6-*eIwxcp#Z0l zD+QcJd9G9_7&)8QWTCndSe`q>ZKJFxQCpuWxq;JEWU|=SPe_Y8eIB6MR%7#Koef|81_~@kHWhkQ`sr5^TVK>u~VM~HsH8CBut<*)h%%Z|;KxG(Tv_a_hNsU+jB>E+Qw`jaPSk9HnPG7%VV z-mpEF_a`e{BnJnYo0^;Y3?aCavnvcHT+yE_`R);6E^@~ZosMPtp70g|G&kpnAsl__ zK$1CzYb|gQ%&qkYV~njDo5*uC&7i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