Skip to content

Commit

Permalink
Add non-null entry check for the MethodList too, so that last entry o…
Browse files Browse the repository at this point in the history
…f the table with 65635 methods and 0 in MethodList index in the last type doesnt crash

(cherry picked from commit 6e37765)
  • Loading branch information
alexey-zakharov committed Nov 7, 2024
1 parent 9b4112a commit 51d6bd0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,18 +634,20 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token, MonoError

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

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

/* reserve space to store vector pointer in arrays */
Expand Down

0 comments on commit 51d6bd0

Please sign in to comment.