fix: messages read into vector are cut off by 4 bytes

This commit is contained in:
Oren Trutner
2025-01-05 08:02:18 -08:00
committed by Nick Bolton
parent b0852bfda5
commit a55fafb4fc
2 changed files with 16 additions and 10 deletions

View File

@ -177,13 +177,6 @@ void ProtocolUtil::vreadf(deskflow::IStream *stream, const char *fmt, va_list ar
case 'I': {
void *destination = va_arg(args, void *);
UInt32 n = read4BytesInt(stream);
if (n > PROTOCOL_MAX_LIST_LENGTH) {
LOG((CLOG_ERR "read: vector length exceeds maximum allowed size: %u", n));
throw XBadClient("Too long message received");
}
switch (len) {
case 1:
// 1 byte integer
@ -493,7 +486,7 @@ UInt32 ProtocolUtil::read4BytesInt(deskflow::IStream *stream)
void ProtocolUtil::readVector1ByteInt(deskflow::IStream *stream, std::vector<UInt8> &destination)
{
UInt32 size = read4BytesInt(stream);
UInt32 size = readVectorSize(stream);
for (UInt32 i = 0; i < size; ++i) {
destination.push_back(read1ByteInt(stream));
}
@ -501,7 +494,7 @@ void ProtocolUtil::readVector1ByteInt(deskflow::IStream *stream, std::vector<UIn
void ProtocolUtil::readVector2BytesInt(deskflow::IStream *stream, std::vector<UInt16> &destination)
{
UInt32 size = read4BytesInt(stream);
UInt32 size = readVectorSize(stream);
for (UInt32 i = 0; i < size; ++i) {
destination.push_back(read2BytesInt(stream));
}
@ -509,12 +502,24 @@ void ProtocolUtil::readVector2BytesInt(deskflow::IStream *stream, std::vector<UI
void ProtocolUtil::readVector4BytesInt(deskflow::IStream *stream, std::vector<UInt32> &destination)
{
UInt32 size = read4BytesInt(stream);
UInt32 size = readVectorSize(stream);
for (UInt32 i = 0; i < size; ++i) {
destination.push_back(read4BytesInt(stream));
}
}
UInt32 ProtocolUtil::readVectorSize(deskflow::IStream *stream)
{
UInt32 size = read4BytesInt(stream);
if (size > PROTOCOL_MAX_LIST_LENGTH) {
LOG((CLOG_ERR "readVectorSize: vector length exceeds maximum allowed size: %u", size));
throw XBadClient("Too long message received");
}
return size;
}
void ProtocolUtil::readBytes(deskflow::IStream *stream, UInt32 len, String *destination)
{
// read the string length

View File

@ -95,6 +95,7 @@ private:
static void readVector1ByteInt(deskflow::IStream *, std::vector<UInt8> &);
static void readVector2BytesInt(deskflow::IStream *, std::vector<UInt16> &);
static void readVector4BytesInt(deskflow::IStream *, std::vector<UInt32> &);
static UInt32 readVectorSize(deskflow::IStream *stream);
/**
* @brief Handles an array of bytes