Prevent a buffer overflow in asset receiving

avinationmerge
Melanie 2012-11-17 02:31:56 +01:00
parent 5cbf7b3997
commit 6faa7fc7f9
1 changed files with 20 additions and 11 deletions

View File

@ -100,19 +100,28 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
if (XferID == xferID) if (XferID == xferID)
{ {
lock (this)
{
int assetLength = m_asset.Data.Length;
int dataLength = data.Length;
if (m_asset.Data.Length > 1) if (m_asset.Data.Length > 1)
{ {
byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; byte[] destinationArray = new byte[assetLength + dataLength];
Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); Array.Copy(m_asset.Data, 0, destinationArray, 0, assetLength);
Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); Array.Copy(data, 0, destinationArray, assetLength, dataLength);
m_asset.Data = destinationArray; m_asset.Data = destinationArray;
} }
else else
{ {
byte[] buffer2 = new byte[data.Length - 4]; if (dataLength > 4)
Array.Copy(data, 4, buffer2, 0, data.Length - 4); {
byte[] buffer2 = new byte[dataLength - 4];
Array.Copy(data, 4, buffer2, 0, dataLength - 4);
m_asset.Data = buffer2; m_asset.Data = buffer2;
} }
}
}
ourClient.SendConfirmXfer(xferID, packetID); ourClient.SendConfirmXfer(xferID, packetID);