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

cpp network module LengthPrefixCodec has a bug #11524

Open
morphad opened this issue Sep 10, 2024 · 0 comments
Open

cpp network module LengthPrefixCodec has a bug #11524

morphad opened this issue Sep 10, 2024 · 0 comments
Assignees

Comments

@morphad
Copy link

morphad commented Sep 10, 2024

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

  1. a call of LengthPrefixCodec::Decode with data length of 3, the packetSize reset to -1, and the packet length will be 3
  2. 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);
            }
@isapego isapego self-assigned this Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants