Skip to content

Commit 0766c5b

Browse files
Merge pull request #2090 from Unity-Technologies/6000.1/bugfixes/fix-fieldlist-65535-fields
[6000.1] [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
2 parents 4d76ea5 + 72fdc88 commit 0766c5b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mono/metadata/class-init.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,20 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError
634634

635635
if (tt->rows > tidx){
636636
mono_metadata_decode_row (tt, tidx, cols_next, MONO_TYPEDEF_SIZE);
637-
field_last = cols_next [MONO_TYPEDEF_FIELD_LIST] - 1;
638-
method_last = cols_next [MONO_TYPEDEF_METHOD_LIST] - 1;
637+
/* check if the next row has fields at all, if not, then continue run till the end of the table */
638+
field_last = cols_next [MONO_TYPEDEF_FIELD_LIST] ? cols_next [MONO_TYPEDEF_FIELD_LIST] - 1 : image->tables [MONO_TABLE_FIELD].rows;
639+
method_last = cols_next [MONO_TYPEDEF_METHOD_LIST] ? cols_next [MONO_TYPEDEF_METHOD_LIST] - 1 : image->tables [MONO_TABLE_METHOD].rows;
639640
} else {
640641
field_last = image->tables [MONO_TABLE_FIELD].rows;
641642
method_last = image->tables [MONO_TABLE_METHOD].rows;
642643
}
643644

645+
/* validate for both fields and methods that class has non-null list entries */
644646
if (cols [MONO_TYPEDEF_FIELD_LIST] &&
645647
cols [MONO_TYPEDEF_FIELD_LIST] <= image->tables [MONO_TABLE_FIELD].rows)
646648
mono_class_set_field_count (klass, field_last - first_field_idx);
647-
if (cols [MONO_TYPEDEF_METHOD_LIST] <= image->tables [MONO_TABLE_METHOD].rows)
649+
if (cols [MONO_TYPEDEF_METHOD_LIST] &&
650+
cols [MONO_TYPEDEF_METHOD_LIST] <= image->tables [MONO_TABLE_METHOD].rows)
648651
mono_class_set_method_count (klass, method_last - first_method_idx);
649652

650653
/* reserve space to store vector pointer in arrays */

0 commit comments

Comments
 (0)