Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in 0.11.3 -- NRE from ILProcessor.InsertBefore() #697

Closed
SteveGilham opened this issue Oct 14, 2020 · 2 comments
Closed

Regression in 0.11.3 -- NRE from ILProcessor.InsertBefore() #697

SteveGilham opened this issue Oct 14, 2020 · 2 comments

Comments

@SteveGilham
Copy link
Contributor

SteveGilham commented Oct 14, 2020

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Mono.Cecil
  StackTrace:
   at Mono.Cecil.Cil.InstructionCollection.ResolveInstructionOffset(InstructionOffset inputOffset, InstructionOffsetCache& cache) in C:\sources\cecil\Mono.Cecil.Cil\MethodBody.cs:line 412
   at Mono.Cecil.Cil.InstructionCollection.UpdateLocalScope(ScopeDebugInformation scope, Instruction removedInstruction, Instruction existingInstruction, InstructionOffsetCache& cache) in C:\sources\cecil\Mono.Cecil.Cil\MethodBody.cs:line 345
   at Mono.Cecil.Cil.InstructionCollection.UpdateLocalScope(ScopeDebugInformation scope, Instruction removedInstruction, Instruction existingInstruction, InstructionOffsetCache& cache) in C:\sources\cecil\Mono.Cecil.Cil\MethodBody.cs:line 356
   at Mono.Cecil.Cil.InstructionCollection.UpdateLocalScopes(Instruction removedInstruction, Instruction existingInstruction) in C:\sources\cecil\Mono.Cecil.Cil\MethodBody.cs:line 334
   at Mono.Collections.Generic.Collection`1.Insert(Int32 index, T item) in C:\sources\cecil\Mono.Collections.Generic\Collection.cs:line 149

Simple repro attached

Cecil.11.3.issue.zip

@SteveGilham
Copy link
Contributor Author

The null reference is the 7th of the 6 instructions in the method body; the initial access to the instructions through the Collection<Instruction> type with size less than capacity decays to a direct access to the internal Instruction[] which has length equal to the capacity.

FWIW, the assembly was built with an old Mono compiler, so advertises a code size of 14, hence the capacity of 7, for 6 instructions.

jbevain added a commit that referenced this issue Oct 15, 2020
* Provoke the issue

* Minimum fix

(cherry picked from commit 0f23047)

* Revert "Provoke the issue"

This reverts commit 1a2275b.

* Add unit test

(cherry picked from commit 185ba88)

* Use existing infrastructure

* Quick fix

Co-authored-by: Jb Evain <[email protected]>
@jbevain
Copy link
Owner

jbevain commented Oct 15, 2020

Fixed in #698.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants