Skip to content

Commit

Permalink
Fixed SOE on deserializing an empty input
Browse files Browse the repository at this point in the history
- Added VdfException type to allow handling invalid input.
- Fixes #5.
  • Loading branch information
shravan2x committed Dec 1, 2017
1 parent 263dc70 commit fd506e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Gameloop.Vdf/VdfException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Gameloop.Vdf
{
public class VdfException : Exception
{
public VdfException(string message) : base(message) { }
}
}
17 changes: 12 additions & 5 deletions Gameloop.Vdf/VdfSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;

namespace Gameloop.Vdf
{
Expand All @@ -23,7 +24,8 @@ public VProperty Deserialize(TextReader textReader)
{
using (VdfReader vdfReader = new VdfTextReader(textReader, _settings))
{
vdfReader.ReadToken();
if (!vdfReader.ReadToken())
throw new VdfException("Incomplete VDF data.");
return ReadProperty(vdfReader);
}
}
Expand All @@ -33,7 +35,9 @@ private VProperty ReadProperty(VdfReader reader)
VProperty result = new VProperty();
result.Key = reader.Value;

reader.ReadToken();
if (!reader.ReadToken())
throw new VdfException("Incomplete VDF data.");

if (reader.CurrentState == VdfReader.State.Property)
result.Value = new VValue(reader.Value);
else
Expand All @@ -46,11 +50,14 @@ private VObject ReadObject(VdfReader reader)
{
VObject result = new VObject();

reader.ReadToken();
if (!reader.ReadToken())
throw new VdfException("Incomplete VDF data.");

while (reader.CurrentState != VdfReader.State.Object || reader.Value != VdfStructure.ObjectEnd.ToString())
{
result.Add(ReadProperty(reader));
reader.ReadToken();
if (!reader.ReadToken())
throw new VdfException("Incomplete VDF data.");
}

return result;
Expand Down

0 comments on commit fd506e2

Please sign in to comment.