Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Avoid an assert if the class name table is too large. #85952

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -11646,11 +11646,15 @@ emit_class_name_table (MonoAotCompile *acfg)
name_p = name_buf = (guint8 *)g_malloc0 (name_buf_size);
#endif

guint table_len = table->len;
if (table_size > 65000 || table->len > 65000) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 65000? (As opposed to 65534 or something)

Do we know how much over the limit the microsoft graph API is? I guess metadata tokens are effectively 24 bits right? so there could be as many as 2^24-1 classes in that assembly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it's kind of too bad that the largest assembly is the one that gets penalized by not having fast name lookup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

65000 is used to avoid having to think about off by one errors. The assembly has about 40k classes, maybe linking is turned off for it.

table_size = 0;
table_len = 0;
}

/* FIXME: Optimize memory usage */
g_assert (table_size < 65000);
encode_int16 (GINT_TO_UINT16 (table_size), p, &p);
g_assert (table->len < 65000);
for (guint i = 0; i < table->len; ++i) {
for (guint i = 0; i < table_len; ++i) {
entry = (ClassNameTableEntry *)g_ptr_array_index (table, i);
if (entry == NULL) {
encode_int16 (0, p, &p);
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,9 @@ mono_aot_get_class_from_name (MonoImage *image, const char *name_space, const ch
table_size = amodule->class_name_table [0];
table = amodule->class_name_table + 1;

if (table_size == 0)
return FALSE;

if (name_space [0] == '\0')
full_name = g_strdup_printf ("%s", name);
else {
Expand Down