[Mono.Profiler.Log] Check MLPD version when reading header
authorRodrigo Moya <rodrigo.moya@xamarin.com>
Fri, 8 Sep 2017 17:36:20 +0000 (19:36 +0200)
committerRodrigo Moya <rodrigo@gnome.org>
Thu, 14 Sep 2017 10:49:27 +0000 (12:49 +0200)
Right now, when reading a MLPD of an old version, it just silently fails, so
throw an exception when the version is unsuported.

mcs/class/Mono.Profiler.Log/Mono.Profiler.Log/LogStreamHeader.cs

index b8eb4413fd7884dfbd6409a8a5d38def590d5bcb..494044d60ce7ce19b8ac724cbe08e2bcfa0da6cf 100644 (file)
@@ -7,6 +7,8 @@ using System;
 namespace Mono.Profiler.Log {
 
        public sealed class LogStreamHeader {
+               const int MinimumMLPDSupportedVersion = 13;
+               const int MaximumMLPDSupportedVersion = 14;
 
                const int Id = 0x4d505a01;
 
@@ -41,6 +43,10 @@ namespace Mono.Profiler.Log {
 
                        Version = new Version (reader.ReadByte (), reader.ReadByte ());
                        FormatVersion = reader.ReadByte ();
+
+                       if (FormatVersion < MinimumMLPDSupportedVersion || FormatVersion > MaximumMLPDSupportedVersion)
+                               throw new LogException ($"Unsupported MLPD version {FormatVersion}. Should be >= {MinimumMLPDSupportedVersion} and <= {MaximumMLPDSupportedVersion}");
+                       
                        PointerSize = reader.ReadByte ();
                        StartupTime = reader.ReadUInt64 ();
                        TimerOverhead = reader.ReadInt32 ();