Bug 27435 - InternalAllocateStr bug with 64-bit build
Summary: InternalAllocateStr bug with 64-bit build
Alias: None
Product: Runtime
Classification: Mono
Component: GC ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Mark Probst
Depends on:
Reported: 2015-02-25 17:44 UTC by Daryl K. Jackson Jr.
Modified: 2015-03-01 19:56 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Tar file with a GNU make file and a C# test file (10.00 KB, application/octet-stream)
2015-02-25 17:44 UTC, Daryl K. Jackson Jr.

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Daryl K. Jackson Jr. 2015-02-25 17:44:30 UTC
Created attachment 10036 [details]
Tar file with a GNU make file and a C# test file

The following:

        {   new StringBuilder(Int32.MaxValue);
            Console.Error.WriteLine("Successful allocation!\n");
        catch (OutOfMemoryException)
        {   Console.Out.WriteLine("Expected exception caught!\n");
        catch (Exception)
        {   Console.Error.WriteLine("OutOfMemoryException should have been thrown!\n");

worked (threw OutOfMemoryException) on my 32-bit Linux distribution with 32-bit builds of Mono versions 3.4.0, 3.10.0, and 3.12.0 but caused a SIGSEGV on all three versions when built and executed on my 64-bit Linux distribution.  Both distributions are Fedora Core 14.  I sued the default compiler.

I was able to fix all three Mono builds on my 64-bit Linux distribution by modifying the following line in the function mono_string_new_size() in mono/metadata/object.c:

    size = (sizeof (MonoString) + ((len + 1) * 2));

Changing it to:

    size = (sizeof (MonoString) + (((size_t) len + 1) * 2));
Comment 1 Zoltan Varga 2015-03-01 19:56:53 UTC
This is already fixed in mono master/mono-4.0.0-branch by d45c58afcd2f8f8c93844864f6015ac82d35e55d.