[
https://issues.apache.org/jira/browse/IGNITE-23598?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17908242#comment-17908242
]
Igor Sapego edited comment on IGNITE-23598 at 12/26/24 10:17 AM:
-----------------------------------------------------------------
Ready for review. [~tmgodinho], can you please take a look?
was (Author: isapego):
Ready for review.
> CPP: Network module LengthPrefixCodec has a bug
> -----------------------------------------------
>
> Key: IGNITE-23598
> URL: https://issues.apache.org/jira/browse/IGNITE-23598
> Project: Ignite
> Issue Type: Bug
> Components: odbc, platforms, thin client
> Affects Versions: 2.16
> Reporter: Igor Sapego
> Assignee: Igor Sapego
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> The bug was originally reported at GitHub by https://github.com/morphad
> (https://github.com/apache/ignite/issues/11524).
> Apparently, there is a bug in 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;
> # The following call, will enter first if, and the packet length of 3 reset
> to 0, the packet last 3 byte data will be lost.
> {code:cpp}
> 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();
> }
> {code}
> Can be fixed like this:
> {code:cpp}
> DataBuffer LengthPrefixCodec::Decode(DataBuffer& data)
> {
> if (packet.IsValid() && packetSize != -1 && packet.Get()->Length() ==
> (PACKET_HEADER_SIZE + packetSize))
> {
> packetSize = -1;
> packet.Get()->Length(0);
> }
> ...
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)