Skip to content

Commit

Permalink
Merge pull request #2055 from MessagePack-CSharp/fixBuggyWrites
Browse files Browse the repository at this point in the history
Fix bugs in serializing long numbers
  • Loading branch information
AArnott authored Nov 2, 2024
2 parents 7c908af + c2cef88 commit d3d435b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ private DecimalFormatter()

public void Serialize(ref MessagePackWriter writer, decimal value, MessagePackSerializerOptions options)
{
var dest = writer.GetSpan(MessagePackRange.MaxFixStringLength);
if (System.Buffers.Text.Utf8Formatter.TryFormat(value, dest.Slice(1), out var written))
var dest = writer.GetSpan(1 + MessagePackRange.MaxFixStringLength);
if (System.Buffers.Text.Utf8Formatter.TryFormat(value, dest.Slice(1, MessagePackRange.MaxFixStringLength), out var written))
{
// write header
dest[0] = (byte)(MessagePackCode.MinFixStr | written);
Expand Down Expand Up @@ -503,7 +503,7 @@ public void Serialize(ref MessagePackWriter writer, System.Numerics.BigInteger v
{
// try to get bin8 buffer.
var span = writer.GetSpan(byte.MaxValue);
if (value.TryWriteBytes(span.Slice(2), out var written))
if (value.TryWriteBytes(span.Slice(2, byte.MaxValue), out var written))
{
span[0] = MessagePackCode.Bin8;
span[1] = (byte)written;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ public void WriteExtensionFormat(ExtensionResult extensionData)
/// <summary>
/// Gets memory where raw messagepack data can be written.
/// </summary>
/// <param name="length">The size of the memory block required.</param>
/// <param name="length">The minimum length of the returned System.Span`1. If 0, a non-empty buffer is returned.</param>
/// <returns>The span of memory to write to. This *may* exceed <paramref name="length"/>.</returns>
/// <remarks>
/// <para>After initializing the resulting memory, always follow up with a call to <see cref="Advance(int)"/>.</para>
Expand Down

0 comments on commit d3d435b

Please sign in to comment.