Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible data corruption from deserializing error details twice #586

Merged
merged 1 commit into from
Oct 19, 2020
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
4 changes: 4 additions & 0 deletions src/StreamJsonRpc/MessagePackFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,10 @@ protected internal override void SetExpectedDataType(Type dataType)
Verify.Operation(!this.MsgPackData.IsEmpty, "Data is no longer available or has already been deserialized.");

this.Data = this.GetData(dataType);

// Clear the source now that we've deserialized to prevent GetData from attempting
// deserialization later when the buffer may be recycled on another thread.
this.MsgPackData = default;
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/StreamJsonRpc/Protocol/JsonRpcError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
namespace StreamJsonRpc.Protocol
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using Microsoft;
using Newtonsoft.Json.Linq;
using StreamJsonRpc.Reflection;

/// <summary>
/// Describes the error resulting from a <see cref="JsonRpcRequest"/> that failed on the server.
Expand Down Expand Up @@ -122,6 +122,11 @@ public class ErrorDetail
/// argument that will be used when calling <see cref="GetData{T}"/> later.
/// </summary>
/// <param name="dataType">The type that will be used as the generic type argument to <see cref="GetData{T}"/>.</param>
/// <remarks>
/// Overridding methods in types that retain buffers used to deserialize should deserialize within this method and clear those buffers
/// to prevent further access to these buffers which may otherwise happen concurrently with a call to <see cref="IJsonRpcMessageBufferManager.DeserializationComplete"/>
/// that would recycle the same buffer being deserialized from.
/// </remarks>
protected internal virtual void SetExpectedDataType(Type dataType)
{
}
Expand Down