Bug 35563 - ASN1 class behaves differently under mono vs dotnet
Summary: ASN1 class behaves differently under mono vs dotnet
Status: RESOLVED DUPLICATE of bug 36295
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/HinTak/Font-Valida...
Depends on:
Reported: 2015-11-04 20:58 UTC by Hin-Tak Leung
Modified: 2017-01-30 17:18 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 Hin-Tak Leung 2015-11-04 20:58:12 UTC
I have the use of processing ASN1 data, while needed to keep dotnet compatibility (ie. cannot
be mono-specfic), so I copied mcs/class/Mono.Security/Mono.Security/ASN1.cs into my project.
Anyway, for the same input, and same binary, built by mcs, somehow the parsing the the same byte stream happens differently
under mono vs dotnet.

ASN1 spc = new ASN1(mydata);

// The structures under mono are:
//         1,0  2,0,0  2,0,1
//         /      \   /
//   0    1        2,0      2,1
//    \  /           \     /
//    self              2
// Under dotnet it is much saner:
//       0,1,0  1,0,0  1,0,1
//         /      \   /
//   0,0  0,1       1,0      1,1
//    \  /           \     /
//      0              1

The number indicates the nodes - i.e. dotnet decomposes the data into spc[0], and spc[1]], which further divides.

But under mono, spc.Value itself contains the first half of my data, while spc[2] contains the 2nd half, and spc[0],
spc[1] are the two halfs of spc.Value.

I use something like this to dump the tree:

for(int i = 0; i< spc.Count; i++)

for(int i = 0; i< spc.Count; i++) {
    Console.WriteLine("Level 2: {0}:{1}" , i,spc[i].Count);
    for(int j = 0; j< spc[i].Count; j++)

for(int i = 0; i< spc.Count; i++)
    for(int j = 0; j< spc[i].Count; j++) {
        Console.WriteLine("Level 3: {0} {1}:{2}" , i,j,spc[i][j].Count);
        for(int k = 0; k< spc[i][j].Count; k++)

The dotnet tree is much saner, but obviously you can't change stuff asd hoc as mono's authenticode depends
on the tree layout, even it if it 'wrong'.

In any case, it is very worrying that same input data, same code and same binary does not give same answer under mono vs dotnet.
Comment 1 Hin-Tak Leung 2015-11-14 00:49:18 UTC
okay, I am glad I can post this now:

The code is this:


The build instruction is on line 25:

mcs /nostdlib /platform:AnyCPU /reference:/usr/lib/mono/2.0/System.dll /reference:/usr/lib/mono/2.0/mscorlib.dll -lib:/usr/lib/mono/2.0 -r:System.Security   DSIGInfo.cs ../mcs-class-Mono.Security/ASN1.cs ../OTFontFile/* ../mcs-class-Mono.Security/ASN1Convert.cs

I currently work around the mono vs dotnet difference around line 128 with:

if ( Type.GetType("Mono.Runtime") == null )

but of course I would refer mono and dotnet runtime works in identical ways.
Comment 2 Hin-Tak Leung 2017-01-30 17:18:51 UTC
My mistake - I did not notice SignedCms.ContentInfo.Content is two byte short under mono. This is a further problem with the System.Security.Cryptography.Pkcs/SignedCms.cs class .

*** This bug has been marked as a duplicate of bug 36295 ***