Skip to content

Commit 4382ff4

Browse files
committed
Adding testing for Process object deserializaion rule
1 parent d72c677 commit 4382ff4

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

LiteDB.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29609.76
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32328.378
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LiteDB", "LiteDB\LiteDB.csproj", "{9497DA19-1FCA-4C2E-A1AB-8DFAACBC76E1}"
77
EndProject

LiteDB/Client/Mapper/BsonMapper.Deserialize.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,20 @@ public object Deserialize(Type type, BsonValue value)
170170
var actualType = _typeNameBinder.GetType(typeField.AsString);
171171

172172
if (actualType == null) throw LiteException.InvalidTypedName(typeField.AsString);
173-
if (!type.IsAssignableFrom(actualType)) throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName);
173+
174+
// avoid initialize class that are not assignable
175+
if (!type.IsAssignableFrom(actualType))
176+
{
177+
throw LiteException.DataTypeNotAssignable(type.FullName, actualType.FullName);
178+
}
179+
180+
// avoid use of "System.Diagnostics.Process" in object type definition
181+
// using String test to work in .netstandard 1.3
182+
if (actualType.FullName.Equals("System.Diagnostics.Process", StringComparison.OrdinalIgnoreCase) &&
183+
actualType.Assembly.GetName().Name.Equals("System", StringComparison.OrdinalIgnoreCase))
184+
{
185+
throw LiteException.AvoidUseOfProcess();
186+
}
174187

175188
type = actualType;
176189
}

LiteDB/LiteDB.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
4+
<TargetFrameworks>net4.5;netstandard1.3;netstandard2.0</TargetFrameworks>
55
<AssemblyVersion>5.0.12</AssemblyVersion>
66
<FileVersion>5.0.12</FileVersion>
77
<VersionPrefix>5.0.12</VersionPrefix>

LiteDB/Utils/LiteException.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class LiteException : Exception
5252
public const int INVALID_NULL_CHAR_STRING = 212;
5353
public const int INVALID_FREE_SPACE_PAGE = 213;
5454
public const int DATA_TYPE_NOT_ASSIGNABLE = 214;
55+
public const int AVOID_USE_OF_PROCESS = 215;
5556

5657
#endregion
5758

@@ -312,6 +313,11 @@ internal static LiteException DataTypeNotAssignable(string type1, string type2)
312313
return new LiteException(DATA_TYPE_NOT_ASSIGNABLE, $"Data type {type1} is not assignable from data type {type2}");
313314
}
314315

316+
internal static LiteException AvoidUseOfProcess()
317+
{
318+
return new LiteException(AVOID_USE_OF_PROCESS, $"LiteDB do not accept System.Diagnostics.Process class in deserialize mapper");
319+
}
320+
315321
#endregion
316322
}
317323
}

0 commit comments

Comments
 (0)