Skip to content

Commit 72fdc88

Browse files
Add non-null entry check for the MethodList too, so that last entry of the table with 65635 methods and 0 in MethodList index in the last type doesnt crash
(cherry picked from commit 6e37765)
1 parent 4bc0dc3 commit 72fdc88

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mono/metadata/class-init.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,18 +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-
// check if the next row has fields at all, if not, then continue run till the end of the table
637+
/* check if the next row has fields at all, if not, then continue run till the end of the table */
638638
field_last = cols_next [MONO_TYPEDEF_FIELD_LIST] ? cols_next [MONO_TYPEDEF_FIELD_LIST] - 1 : image->tables [MONO_TABLE_FIELD].rows;
639639
method_last = cols_next [MONO_TYPEDEF_METHOD_LIST] ? cols_next [MONO_TYPEDEF_METHOD_LIST] - 1 : image->tables [MONO_TABLE_METHOD].rows;
640640
} else {
641641
field_last = image->tables [MONO_TABLE_FIELD].rows;
642642
method_last = image->tables [MONO_TABLE_METHOD].rows;
643643
}
644644

645+
/* validate for both fields and methods that class has non-null list entries */
645646
if (cols [MONO_TYPEDEF_FIELD_LIST] &&
646647
cols [MONO_TYPEDEF_FIELD_LIST] <= image->tables [MONO_TABLE_FIELD].rows)
647648
mono_class_set_field_count (klass, field_last - first_field_idx);
648-
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)
649651
mono_class_set_method_count (klass, method_last - first_method_idx);
650652

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

0 commit comments

Comments
 (0)