Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1baf212

Browse files
committed
prevent StackOverflow Exception in ValueTypeConverter
1 parent 19c2c8d commit 1baf212

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/ServiceStack.OrmLite/Converters/SpecialConverters.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ public override object ToDbValue(Type fieldType, object value)
155155

156156
public override object FromDbValue(Type fieldType, object value)
157157
{
158-
return DialectProvider.FromDbValue(value, fieldType);
158+
if (fieldType.IsInstanceOfType(value))
159+
return value;
160+
161+
var convertedValue = DialectProvider.StringSerializer.DeserializeFromString(value.ToString(), fieldType);
162+
return convertedValue;
159163
}
160164
}
161165
}

tests/ServiceStack.OrmLite.Tests/ConverterTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ namespace ServiceStack.OrmLite.Tests
1010
[TestFixture]
1111
public class ConverterTests : OrmLiteTestBase
1212
{
13-
private struct TestStruct
14-
{
15-
}
13+
private struct TestStruct {}
1614

17-
[Test, Explicit]
18-
public void FromDbValue_StackOverflowException()
15+
[Test]
16+
public void FromDbValue_does_not_throw_Exception()
1917
{
2018
var dialectProvider = OrmLiteConfig.DialectProvider;
21-
var convertedValue = dialectProvider.FromDbValue(12345, typeof(TestStruct)); // StackOverflowException in v4.0.54
19+
var convertedValue = dialectProvider.FromDbValue(12345, typeof(TestStruct));
2220
Assert.That(convertedValue, Is.Null);
2321
}
2422

0 commit comments

Comments
 (0)