[runtime] Fix string size calculation in `mono_string_new_size()`.
authorMark Probst <mark.probst@gmail.com>
Tue, 9 Dec 2014 21:15:55 +0000 (13:15 -0800)
committerMark Probst <mark.probst@gmail.com>
Tue, 9 Dec 2014 21:16:25 +0000 (13:16 -0800)
This bug is not hit when doing managed allocations with SGen because the
managed allocator catches it.  It can be triggered with the embedding API, as
well as when the heavy binary protocol is enabled, in which case `bug-17590`
fails.

mono/metadata/object.c

index d69dfafe1cfa21e05d044fe18f08a055a81bd597..913e94f3c3116d20d01d495fda8236f400bf0668 100644 (file)
@@ -5060,7 +5060,7 @@ mono_string_new_size (MonoDomain *domain, gint32 len)
        if (len < 0 || len > ((SIZE_MAX - G_STRUCT_OFFSET (MonoString, chars) - 2) / 2))
                mono_gc_out_of_memory (-1);
 
-       size = (G_STRUCT_OFFSET (MonoString, chars) + ((len + 1) * 2));
+       size = (G_STRUCT_OFFSET (MonoString, chars) + (((size_t)len + 1) * 2));
        g_assert (size > 0);
 
        vtable = mono_class_vtable (domain, mono_defaults.string_class);