Bug 13970 - Guid.Parse does not throw FormatException when missing single trailing char in segment
Summary: Guid.Parse does not throw FormatException when missing single trailing char i...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2013-08-14 09:15 UTC by Tomasz Cielecki
Modified: 2013-08-15 07:59 UTC (History)
2 users (show)

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

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 Tomasz Cielecki 2013-08-14 09:15:07 UTC
When using Guid.Parse() on a string containing a Guid representation the expected format is one of the Formats in https://github.com/mono/mono/blob/master/mcs/class/corlib/System/Guid.cs#L71. 

However, I have encountered that Guid.Parse() also accepts the format xxxxxx-xxx-xxx-xxx-xxxxxxxxxxx. So the segment lengths are 7-3-3-3-11. 
When using Microsoft's .NET a FormatException is thrown, when using that format, in mono no exception is thrown and the format is accepted.
The resulting Guid when parsing 8888888-444-444-444-12121212121, which uses that format, is 08888888-0444-0444-4404-121212121201. I have found that each segment in the format can have one optional missing character and no FormatException is thrown, if more are missing it is throwing the Exception correctly.

I suppose the parser has a limit error in one of it's loops. I can reproduce this in Xamarin.Android and on MacOS X, which both run Mono 3.
Comment 1 Marek Safar 2013-08-15 06:21:07 UTC
Fixed in master.

I could not confirm your claim that each segment in the format can have one optional missing character. Do you have test case for that?
Comment 2 Tomasz Cielecki 2013-08-15 07:59:04 UTC
For a simple test case I ran csharp in the console on the Mac:

csharp> var myguid = Guid.Parse("8888888-444-444-444-12121212121");
csharp> myguid.ToString();

If you look at the Guid I am trying to parse it is missing one char in each segment.

I can reproduce with the following strings:

And they can be combined so that i.e. 2 segments are missing a char etc.

mono --version
Mono JIT compiler version 3.2.1 ((no/f3f789e Tue Jul 30 00:31:23 EDT 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.3svn-mono)
	GC:            sgen