Skip to content

Commit

Permalink
fixes #180
Browse files Browse the repository at this point in the history
  • Loading branch information
jefffhaynes committed Dec 23, 2021
1 parent d8e76b0 commit 675f212
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
35 changes: 35 additions & 0 deletions BinarySerializer.Test/Issues/Issue180/Issue180Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BinarySerialization.Test.Issues.Issue180
{
[TestClass]
public class Issue180Tests : TestBase
{
public class BitFieldsPrecededByByte
{
[FieldOrder(0)]
public byte First;

[FieldOrder(1)]
[FieldBitLength(7)]
public byte SevenBits;

[FieldOrder(2)]
[FieldBitLength(1)]
public byte OneBit;
}

[TestMethod]
public void TestOutOfMemory()
{
for (int i = 0; i < 7; i++)
{
Console.WriteLine($"Trying to deserialize array of partial {nameof(BitFieldsPrecededByByte)} with array size {i}");
var serialized = new byte[i];
// This call will never return and consumes all available memory
var _ = Deserialize<BitFieldsPrecededByByte[]>(serialized);
}
}
}
}
8 changes: 4 additions & 4 deletions BinarySerializer/BinarySerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<Description>A declarative serialization framework for controlling formatting of data using field bindings.</Description>
<AssemblyName>BinarySerializer</AssemblyName>
<PackageTags>Serialization;Serializer;Binary;Format;Protocol</PackageTags>
<PackageReleaseNotes>Additional comparison operator support in conditional serialization</PackageReleaseNotes>
<PackageReleaseNotes>Bug fix for end-of-stream during collection deserialization</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/jefffhaynes/BinarySerializer</PackageProjectUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/jefffhaynes/BinarySerializer</RepositoryUrl>
<AssemblyVersion>8.6.2</AssemblyVersion>
<FileVersion>8.6.2</FileVersion>
<Version>8.6.2</Version>
<AssemblyVersion>8.6.2.1</AssemblyVersion>
<FileVersion>8.6.2.1</FileVersion>
<Version>8.6.2.1</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Jeff Haynes</Authors>
<Company />
Expand Down
5 changes: 5 additions & 0 deletions BinarySerializer/Graph/ValueGraph/CollectionValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ internal override async Task DeserializeOverrideAsync(BoundedStream stream, Even
await child.DeserializeAsync(childStream, eventShuttle, cancellationToken)
.ConfigureAwait(false);

if (child.Value == null)
{
break;
}

if (IsTerminated(child, itemTerminationValue))
{
ProcessLastItem(streamResetter, child);
Expand Down

0 comments on commit 675f212

Please sign in to comment.