Hi,

I have found the following bug in Cecil. Here is how to trigger it: Make an assembly with a method where the last instruction in that method is also the last instruction in a handler block. Use Cecil to load the assembly and then save it. This will result in a NullReferenceException being thrown from Mono.Cecil.Cil.CodeWriter.IsRangeFat. I have attached an example assembly that contains such a method.

The problem is that Cecil represents a range of consecutive instructions as a reference to the first instruction in the range and a reference to the instruction just past the end of the range. This design breaks down if the end of the range is the last instruction, so that there are no instructions past it. When Cecil reads a range of that kind, it will set the end pointer of the range to null, but when it writes the range, it assumes that the end pointer is not null.

If you are using Cecil, you can work around this bug by adding a dummy return instruction to the end of methods that has this problem. Then the dummy return instruction can be set as the HandlerEnd of the block, thus avoiding the problem.

It would probably be a good idea to document how ranges are represented in Cecil in the FAQ, as there are several reasonable ways it could work, and it is not possible to tell from the Cecil interface which one it is.

I also have a question: I have an example of an assembly output by the MS C# compiler that shrinks from 3.072 bytes to 2.048 bytes simply by loading and then saving it using Cecil. How does that happen?

Regards
Bjarke Roune

Attachment: bug
Description: Binary data

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to