Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -500,54 +500,61 @@ internal void ProcessRawData(byte[] data, OnDataAvailableCallback callback)
}

int totalLengthOfFragment = 0;
int totalSizeToBeReceived = 0;

try
{
totalLengthOfFragment = checked(FragmentedRemoteObject.HeaderLength + blobLength);
}
catch (System.OverflowException)
catch (OverflowException)
{
s_baseTracer.WriteLine("Fragment too big.");
ResetReceiveData();
PSRemotingTransportException e = new PSRemotingTransportException(RemotingErrorIdStrings.ObjectIsTooBig);
throw e;
}

if (_pendingDataStream.Length < totalLengthOfFragment)
{
s_baseTracer.WriteLine("Not enough data to process packet. Data is less than expected blob length. Data length {0}. Expected Length {1}.",
_pendingDataStream.Length, totalLengthOfFragment);
return;
}

// ensure object size limit is not reached
// Ensure object size limit is not reached
if (_maxReceivedObjectSize.HasValue)
{
_totalReceivedObjectSizeSoFar = unchecked(_totalReceivedObjectSizeSoFar + totalLengthOfFragment);
if ((_totalReceivedObjectSizeSoFar < 0) || (_totalReceivedObjectSizeSoFar > _maxReceivedObjectSize.Value))
totalSizeToBeReceived = unchecked(_totalReceivedObjectSizeSoFar + totalLengthOfFragment);
if (totalSizeToBeReceived < 0 || totalSizeToBeReceived > _maxReceivedObjectSize.Value)
{
s_baseTracer.WriteLine("ObjectSize > MaxReceivedObjectSize. ObjectSize is {0}. MaxReceivedObjectSize is {1}",
_totalReceivedObjectSizeSoFar, _maxReceivedObjectSize);
totalSizeToBeReceived, _maxReceivedObjectSize);
PSRemotingTransportException e = null;

if (_isCreateByClientTM)
{
e = new PSRemotingTransportException(PSRemotingErrorId.ReceivedObjectSizeExceededMaximumClient,
RemotingErrorIdStrings.ReceivedObjectSizeExceededMaximumClient,
_totalReceivedObjectSizeSoFar, _maxReceivedObjectSize);
totalSizeToBeReceived, _maxReceivedObjectSize);
}
else
{
e = new PSRemotingTransportException(PSRemotingErrorId.ReceivedObjectSizeExceededMaximumServer,
RemotingErrorIdStrings.ReceivedObjectSizeExceededMaximumServer,
_totalReceivedObjectSizeSoFar, _maxReceivedObjectSize);
totalSizeToBeReceived, _maxReceivedObjectSize);
}

ResetReceiveData();
throw e;
}
}

if (_pendingDataStream.Length < totalLengthOfFragment)
{
s_baseTracer.WriteLine("Not enough data to process packet. Data is less than expected blob length. Data length {0}. Expected Length {1}.",
_pendingDataStream.Length, totalLengthOfFragment);
return;
}

// Update the real object size we received so far only when we have received the complete fragment.
if (_maxReceivedObjectSize.HasValue)
{
_totalReceivedObjectSizeSoFar = totalSizeToBeReceived;
}

// appears like stream doesn't have individual position marker for read and write
// since we are going to read from now...
_pendingDataStream.Seek(0, SeekOrigin.Begin);
Expand Down
Loading