From 4382ff4dd0dd8b8b16a4e37dfd29727c5f70f93f Mon Sep 17 00:00:00 2001 From: Mauricio David Date: Thu, 8 Dec 2022 12:03:28 -0300 Subject: [PATCH] Adding testing for Process object deserializaion rule --- LiteDB.sln | 4 ++-- LiteDB/Client/Mapper/BsonMapper.Deserialize.cs | 15 ++++++++++++++- LiteDB/LiteDB.csproj | 2 +- LiteDB/Utils/LiteException.cs | 6 ++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/LiteDB.sln b/LiteDB.sln index 1d02cb641..848dbb661 100644 --- a/LiteDB.sln +++ b/LiteDB.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29609.76 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32328.378 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiteDB", "LiteDB\LiteDB.csproj", "{9497DA19-1FCA-4C2E-A1AB-8DFAACBC76E1}" EndProject diff --git a/LiteDB/Client/Mapper/BsonMapper.Deserialize.cs b/LiteDB/Client/Mapper/BsonMapper.Deserialize.cs index 5660db622..f347ae523 100644 --- a/LiteDB/Client/Mapper/BsonMapper.Deserialize.cs +++ b/LiteDB/Client/Mapper/BsonMapper.Deserialize.cs @@ -170,7 +170,20 @@ public object Deserialize(Type type, BsonValue value) var actualType = _typeNameBinder.GetType(typeField.AsString); if (actualType == null) throw LiteException.InvalidTypedName(typeField.AsString); - if (!type.IsAssignableFrom(actualType)) throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName); + + // avoid initialize class that are not assignable + if (!type.IsAssignableFrom(actualType)) + { + throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName); + } + + // avoid use of "System.Diagnostics.Process" in object type definition + // using String test to work in .netstandard 1.3 + if (actualType.FullName.Equals("System.Diagnostics.Process", StringComparison.OrdinalIgnoreCase) && + actualType.Assembly.GetName().Name.Equals("System", StringComparison.OrdinalIgnoreCase)) + { + throw LiteException.AvoidUseOfProcess(); + } type = actualType; } diff --git a/LiteDB/LiteDB.csproj b/LiteDB/LiteDB.csproj index cbc9b0446..58865570c 100644 --- a/LiteDB/LiteDB.csproj +++ b/LiteDB/LiteDB.csproj @@ -1,7 +1,7 @@  - net45;netstandard1.3;netstandard2.0 + net4.5;netstandard1.3;netstandard2.0 5.0.12 5.0.12 5.0.12 diff --git a/LiteDB/Utils/LiteException.cs b/LiteDB/Utils/LiteException.cs index a27dc3c85..2a123104d 100644 --- a/LiteDB/Utils/LiteException.cs +++ b/LiteDB/Utils/LiteException.cs @@ -52,6 +52,7 @@ public class LiteException : Exception public const int INVALID_NULL_CHAR_STRING = 212; public const int INVALID_FREE_SPACE_PAGE = 213; public const int DATA_TYPE_NOT_ASSIGNABLE = 214; + public const int AVOID_USE_OF_PROCESS = 215; #endregion @@ -312,6 +313,11 @@ internal static LiteException DataTypeNotAssignable(string type1, string type2) return new LiteException(DATA_TYPE_NOT_ASSIGNABLE, $"Data type {type1} is not assignable from data type {type2}"); } + internal static LiteException AvoidUseOfProcess() + { + return new LiteException(AVOID_USE_OF_PROCESS, $"LiteDB do not accept System.Diagnostics.Process class in deserialize mapper"); + } + #endregion } } \ No newline at end of file