msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

Possible BUG in SingleArrayBufferAllocator.cs

Open gviolator opened this issue 7 years ago • 1 comments

	private static byte[] Allocate( byte[] old, int requestSize )
		{
			if ( old.Length < 256 )
			{
				return new byte[ 256 ];
			}

			// Use golden ratio to improve linear memory range reusability (of LOH)
			var newSize = Math.Max( ( long )( old.Length * 1.1618 ), requestSize + ( long )old.Length );
			if ( newSize > Int32.MaxValue )
			{
				return null;
			}

			return new byte[ newSize ];
		}

May be instead of

if ( old.Length < 256 )

should be

if (requestSize  < 256 )

Because if requested buffer size is greater than 256 and current buffer's length is less than 256 (for example we just serialize big string), then we fail to allocate, and whole serialization process will fail ...

gviolator avatar Mar 05 '18 13:03 gviolator

Thank you for reporting. I'll add test case for this, and then fix for 1.0.

yfakariya avatar Mar 26 '18 13:03 yfakariya