diff options
author | Jb Evain <jb@evain.net> | 2021-07-03 00:08:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 00:08:04 +0300 |
commit | ede17f98c9dd9396f9b3f4079af166a784e4baac (patch) | |
tree | dc1dade7914102067696949a7407460f5247e419 | |
parent | 04b44978799b4c5268955de2219cda45904aa397 (diff) |
Fix handling of empty string constants (#776)
-rw-r--r-- | Mono.Cecil/AssemblyReader.cs | 4 | ||||
-rw-r--r-- | Test/Mono.Cecil.Tests/PortablePdbTests.cs | 17 | ||||
-rw-r--r-- | Test/Resources/assemblies/empty-str-const.exe | bin | 0 -> 4096 bytes | |||
-rw-r--r-- | Test/Resources/assemblies/empty-str-const.pdb | bin | 0 -> 2668 bytes |
4 files changed, 20 insertions, 1 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index 5cd3d17..b66c162 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -3005,7 +3005,9 @@ namespace Mono.Cecil { 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 43b8cfe..d9786cb 100644 --- a/Test/Mono.Cecil.Tests/PortablePdbTests.cs +++ b/Test/Mono.Cecil.Tests/PortablePdbTests.cs @@ -475,6 +475,23 @@ namespace Mono.Cecil.Tests { } [Test] + public void EmptyStringLocalConstant () + { + TestModule ("empty-str-const.exe", module => { + var type = module.GetType ("<Program>$"); + var method = type.GetMethod ("<Main>$"); + 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 () { TestModule ("TargetLib.dll", module => { diff --git a/Test/Resources/assemblies/empty-str-const.exe b/Test/Resources/assemblies/empty-str-const.exe Binary files differnew file mode 100644 index 0000000..6cc5128 --- /dev/null +++ b/Test/Resources/assemblies/empty-str-const.exe diff --git a/Test/Resources/assemblies/empty-str-const.pdb b/Test/Resources/assemblies/empty-str-const.pdb Binary files differnew file mode 100644 index 0000000..723ec4e --- /dev/null +++ b/Test/Resources/assemblies/empty-str-const.pdb |