[UUM-78961] Fixed initialization of a class which has last fields in a table with 65535 field entries and the next class having no fields #2081
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UUM-78961 Fixed initialization of a class which has last fields in a table with 65535 field entries and the next class having no fields.
Mono crashes on allocation when initializing a class which has fields or methods that run till the end of the metadata table and the last TypeDef has no fields. This happens die to the last TypeDef without any fields having FieldList index 0 (null field).
The assembly was generated by Mono.Cecil in IL postrpocessor and thus several fix options were considered:
There are several related sections in the ECMA-335 standard interpreting which lead to the current fix.
II.22.37 TypeDef : 0x02
sectionII.22.37 TypeDef : 0x02
"This contains informative text only" sectionII.24.2.6 #~ stream
sectionFixing Mono.Cecil to use large indices for the FieldList doesn't play well with
II.24.2.6 #~ stream
section as every existing reader won't be able to read the generated assembly.Fixing IL postprocessor to generate a dummy field fixes that specific postprocessor usage case and won't fix loading any other assembly compiled externally.
I think fixing mono is the best option as it would ensure we can load assembly with this edge case metadata table generated by other sources too (cecil, netcore compiler, etc).
The current fix addressed FieldList and MethodList cases.
Related discussions:
Reviewers: please consider these questions as well! ❤️
Release notes
Fixed UUM-78961 @alexeyzakharov:
Mono: Fixed crash when loading a class which contains fields at the end of the metadata table with a table size 65535.
Backports
6, 2022.3