ignite
ignite copied to clipboard
cpp network module LengthPrefixCodec has a bug
when using ignite cpp thin client, we find a bug of LengthPrefixCodec::Decode function, in file modules/platforms/cpp/network/src/network/length_prefix_codec.cpp
- a call of LengthPrefixCodec::Decode with data length of 3, the packetSize reset to -1, and the packet length will be 3
- following call, will enter first if, and the packet length of 3 reset to 0, the packet last 3 byte data will be lost
DataBuffer LengthPrefixCodec::Decode(DataBuffer& data)
{
if (packet.IsValid() && packet.Get()->Length() == (PACKET_HEADER_SIZE + packetSize))
{
packetSize = -1;
packet.Get()->Length(0);
}
if (packetSize < 0)
{
Consume(data, PACKET_HEADER_SIZE);
if (packet.Get()->Length() < PACKET_HEADER_SIZE)
return DataBuffer();
packetSize = impl::binary::BinaryUtils::ReadInt32(*packet.Get(), 0);
}
Consume(data, PACKET_HEADER_SIZE + packetSize);
if (packet.Get()->Length() == (PACKET_HEADER_SIZE + packetSize))
return DataBuffer(packet, 0, PACKET_HEADER_SIZE + packetSize);
return DataBuffer();
}
can be fix as :
DataBuffer LengthPrefixCodec::Decode(DataBuffer& data)
{
if (packet.IsValid() && packetSize != -1 && packet.Get()->Length() == (PACKET_HEADER_SIZE + packetSize))
{
packetSize = -1;
packet.Get()->Length(0);
}