Bug 5464 - Convert.FromBase64String behaviour deviates between mono and .NET
Summary: Convert.FromBase64String behaviour deviates between mono and .NET
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2012-06-01 18:37 UTC by Brandon Perry
Modified: 2012-06-19 22:13 UTC (History)
4 users (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Brandon Perry 2012-06-01 18:37:27 UTC
I was passed some malformed base64 data, and .NET throws an exception when trying to convert the string to some bytes. Mono on the other hand passes it over just fine and I get exactly what I expect from converting it.


using System;

namespace base64_test
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			byte[] bytes = Convert.FromBase64String("dGVzdA==DQo=");
			
			string stuff = System.Text.Encoding.ASCII.GetString(bytes);
			
			Console.WriteLine(stuff);
		}
	}
}


My mono version:
bperry@w00den-pickle:~$ mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            Included Boehm (with typed GC and Parallel Mark)
bperry@w00den-pickle:~$ 


Targeting 4.0 in both runs in mono and .NET
Comment 1 Brandon Perry 2012-06-01 18:43:05 UTC
Unhandled Exception: System.FormatException: The input is not a valid Base-64 st
ring as it contains a non-base 64 character, more than two padding characters, o
r a non-white space character among the padding characters.
   at System.Convert.FromBase64String(String s)
   at base64_test.Program.Main(String[] args) in C:\Documents and Settings\fgsd\
Local Settings\Application Data\Temporary Projects\base64_test\Program.cs:line 1
3

C:\Documents and Settings\fgsd\My Documents\Visual Studio 2010\Projects\base64_t
est\base64_test\bin\Debug>base64_test.exe
The input is not a valid Base-64 string as it contains a non-base 64 character,
more than two padding characters, or a non-white space character among the paddi
ng characters.
   at System.Convert.FromBase64String(String s)
   at base64_test.Program.Main(String[] args) in C:\Documents and Settings\fgsd\
my documents\visual studio 2010\Projects\base64_test\base64_test\Program.cs:line
 15

Here is the stacktrace on .NET. The line numbers won't line up exactly since I threw it into a try/catch and printed out the stacktrace and message.
Comment 2 Adam Brengesjö 2012-06-13 19:39:15 UTC
https://github.com/mono/mono/pull/325
Comment 3 Martin Baulig 2012-06-19 14:01:56 UTC
I applied your patch and also added an additional test case for "dGVzd===".
Comment 4 Martin Baulig 2012-06-19 15:30:19 UTC
Fixed; commits 25981a0 and 8f13973.
Comment 5 Miguel de Icaza [MSFT] 2012-06-19 16:57:05 UTC
Did you remember to git push?