Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,15 @@ Release 0.9.0 2017-8-26
* Fix MessagePackSerializer.Capability does not work correctly in Unity.
* Fix polymorphic serializer error in Unity.

Release 0.9.1 2017-8-30

BUG FIXES
* Fix ByteArrayPacker throws IndexOutOfBoundException when the buffer remaining bytes is equal to packed scalar size. #252

Release 1.0.0-beta1 T.B.D.

NEW FEATURES
* .NET Standard 2.0 which supports serializer source code generation on .NET Core. Note that serializer assembly generation is not supported.

BUG FIXES
* Fix ByteArrayPacker throws IndexOutOfBoundException when the buffer remaining bytes is equal to packed scalar size. #252
32 changes: 19 additions & 13 deletions src/MsgPack/MessagePackByteArrayPacker.Pack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


#region -- License Terms --
//
// MessagePack for CLI
Expand Down Expand Up @@ -981,9 +981,10 @@ private void WriteBytes( byte header, byte value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( byte ) && !this._allocator.TryAllocate( buffer, sizeof( byte ), out buffer ) )
const int requiredSize = sizeof( byte ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( byte ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand All @@ -1000,9 +1001,10 @@ private void WriteBytes( byte header, ushort value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( ushort ) && !this._allocator.TryAllocate( buffer, sizeof( ushort ), out buffer ) )
const int requiredSize = sizeof( ushort ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( ushort ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand All @@ -1020,9 +1022,10 @@ private void WriteBytes( byte header, uint value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( uint ) && !this._allocator.TryAllocate( buffer, sizeof( uint ), out buffer ) )
const int requiredSize = sizeof( uint ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( uint ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand All @@ -1042,9 +1045,10 @@ private void WriteBytes( byte header, ulong value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( ulong ) && !this._allocator.TryAllocate( buffer, sizeof( ulong ), out buffer ) )
const int requiredSize = sizeof( ulong ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( ulong ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand All @@ -1069,9 +1073,10 @@ private void WriteBytes( byte header, float value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( float ) && !this._allocator.TryAllocate( buffer, sizeof( float ), out buffer ) )
const int requiredSize = sizeof( float ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( float ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand All @@ -1092,9 +1097,10 @@ private void WriteBytes( byte header, double value )
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( double ) && !this._allocator.TryAllocate( buffer, sizeof( double ), out buffer ) )
const int requiredSize = sizeof( double ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( double ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand Down
7 changes: 4 additions & 3 deletions src/MsgPack/MessagePackByteArrayPacker.Pack.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<#@ template debug="true" hostSpecific="true" language="C#" #>
<#@ template debug="true" hostSpecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ import namespace="System" #>
Expand Down Expand Up @@ -77,9 +77,10 @@ namespace MsgPack
var buffer = this._buffer;
var offset = this._offset;
var remains = buffer.Length - offset;
if ( remains < sizeof( <#= type #> ) && !this._allocator.TryAllocate( buffer, sizeof( <#= type #> ), out buffer ) )
const int requiredSize = sizeof( <#= type #> ) + 1;
if ( remains < requiredSize && !this._allocator.TryAllocate( buffer, requiredSize, out buffer ) )
{
this.ThrowEofException( sizeof( <#= type #> ) );
this.ThrowEofException( requiredSize );
}

buffer[ offset ] = header;
Expand Down
18 changes: 17 additions & 1 deletion test/MsgPack.UnitTest/Serialization/RegressionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region -- License Terms --
#region -- License Terms --
//
// MessagePack for CLI
//
Expand Down Expand Up @@ -446,5 +446,21 @@ public class SingleValueObject
{
public string Value { get; set; }
}

[Test]
public void TestIssue252()
{
var context = new SerializationContext();
var serializer = context.GetSerializer<Issue252Class>();
var bytes = serializer.PackSingleObject( new Issue252Class() );
Assert.That( bytes.Length, Is.EqualTo( MessagePackSerializer.BufferSize + 1 ), Binary.ToHexString( bytes ) );
}

public class Issue252Class
{
// BufferSize - sizeof( Int32 property ) - sizeof( byte array type header with 1bit length ) - sizeof( array header );
public byte[] ByteArray = new byte[ MessagePackSerializer.BufferSize - sizeof( int ) - sizeof( byte ) - 1 - 1 ];
public int Int32 = Int32.MaxValue;
}
}
}