You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 15:46:33 +09:00
Fixed issue with very large encrypted message
This commit is contained in:
@@ -35,7 +35,7 @@ namespace Lidgren.Network
|
|||||||
int numBlocks = (int)Math.Ceiling((double)numBytes / (double)blockSize);
|
int numBlocks = (int)Math.Ceiling((double)numBytes / (double)blockSize);
|
||||||
int dstSize = numBlocks * blockSize;
|
int dstSize = numBlocks * blockSize;
|
||||||
|
|
||||||
msg.EnsureBufferSize(dstSize * 8 + 2); // add 2 bytes for payload length at end
|
msg.EnsureBufferSize(dstSize * 8 + (4 * 8)); // add 4 bytes for payload length at end
|
||||||
msg.LengthBits = dstSize * 8; // length will automatically adjust +4 bytes when payload length is written
|
msg.LengthBits = dstSize * 8; // length will automatically adjust +4 bytes when payload length is written
|
||||||
|
|
||||||
for(int i=0;i<numBlocks;i++)
|
for(int i=0;i<numBlocks;i++)
|
||||||
@@ -45,7 +45,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add true payload length last
|
// add true payload length last
|
||||||
msg.Write((ushort)payloadBitLength);
|
msg.Write((UInt32)payloadBitLength);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ namespace Lidgren.Network
|
|||||||
/// <returns>true if successful; false if failed</returns>
|
/// <returns>true if successful; false if failed</returns>
|
||||||
public bool Decrypt(NetIncomingMessage msg)
|
public bool Decrypt(NetIncomingMessage msg)
|
||||||
{
|
{
|
||||||
int numEncryptedBytes = msg.LengthBytes - 2; // last 2 bytes is true bit length
|
int numEncryptedBytes = msg.LengthBytes - 4; // last 4 bytes is true bit length
|
||||||
int blockSize = BlockSize;
|
int blockSize = BlockSize;
|
||||||
int numBlocks = numEncryptedBytes / blockSize;
|
int numBlocks = numEncryptedBytes / blockSize;
|
||||||
if (numBlocks * blockSize != numEncryptedBytes)
|
if (numBlocks * blockSize != numEncryptedBytes)
|
||||||
@@ -69,8 +69,8 @@ namespace Lidgren.Network
|
|||||||
Buffer.BlockCopy(m_tmp, 0, msg.m_data, (i * blockSize), m_tmp.Length);
|
Buffer.BlockCopy(m_tmp, 0, msg.m_data, (i * blockSize), m_tmp.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read 16 bits of true payload length
|
// read 32 bits of true payload length
|
||||||
uint realSize = NetBitWriter.ReadUInt32(msg.m_data, 16, (numEncryptedBytes * 8));
|
uint realSize = NetBitWriter.ReadUInt32(msg.m_data, 32, (numEncryptedBytes * 8));
|
||||||
msg.m_bitLength = (int)realSize;
|
msg.m_bitLength = (int)realSize;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -438,17 +438,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(source);
|
byte[] bytes = Encoding.UTF8.GetBytes(source);
|
||||||
|
InternalEnsureBufferSize(m_bitLength + ((bytes.Length + 2) * 8));
|
||||||
// determine number of bytes to store length
|
|
||||||
int lenBytesNeeded = 1;
|
|
||||||
uint num1 = (uint)bytes.Length;
|
|
||||||
while (num1 >= 0x80)
|
|
||||||
{
|
|
||||||
num1 = num1 >> 7;
|
|
||||||
lenBytesNeeded++;
|
|
||||||
}
|
|
||||||
InternalEnsureBufferSize(m_bitLength + ((bytes.Length + lenBytesNeeded) * 8));
|
|
||||||
|
|
||||||
WriteVariableUInt32((uint)bytes.Length);
|
WriteVariableUInt32((uint)bytes.Length);
|
||||||
Write(bytes);
|
Write(bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user