1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-05 16:15:50 +03:00

Handle error during parsing of bytestream.

The error can occur in case we send the bytestream with `old` format header.
This commit is contained in:
Denis Khalikov
2021-12-30 10:12:23 +03:00
parent 97aec525fb
commit 6dab174fd3

View File

@@ -598,37 +598,49 @@ const SBS InetStreamSocket::read(const struct ::timespec* timeout, bool* isTimeO
res->advanceInputPtr(msglen); res->advanceInputPtr(msglen);
std::vector<boost::shared_array<uint8_t>> longStrings; std::vector<boost::shared_array<uint8_t>> longStrings;
longStrings.reserve(longStringSize); try
for (uint32_t i = 0; i < longStringSize; ++i)
{ {
// Read `MemChunk`. for (uint32_t i = 0; i < longStringSize; ++i)
rowgroup::StringStore::MemChunk memChunk; {
if (!readFixedSizeData(pfd, reinterpret_cast<uint8_t*>(&memChunk), // Read `MemChunk`.
sizeof(rowgroup::StringStore::MemChunk), timeout, isTimeOut, stats, rowgroup::StringStore::MemChunk memChunk;
msecs)) if (!readFixedSizeData(pfd, reinterpret_cast<uint8_t*>(&memChunk),
return SBS(new ByteStream(0)); sizeof(rowgroup::StringStore::MemChunk), timeout, isTimeOut,
stats, msecs))
return SBS(new ByteStream(0));
// Allocate new memory for the `long string`. // Allocate new memory for the `long string`.
boost::shared_array<uint8_t> longString( boost::shared_array<uint8_t> longString(
new uint8_t[sizeof(rowgroup::StringStore::MemChunk) + memChunk.currentSize]); new uint8_t[sizeof(rowgroup::StringStore::MemChunk) + memChunk.currentSize]);
uint8_t* longStringData = longString.get(); uint8_t* longStringData = longString.get();
// Initialize memchunk with `current size` and `capacity`. // Initialize memchunk with `current size` and `capacity`.
auto* memChunkPointer = reinterpret_cast<rowgroup::StringStore::MemChunk*>(longStringData); auto* memChunkPointer =
memChunkPointer->currentSize = memChunk.currentSize; reinterpret_cast<rowgroup::StringStore::MemChunk*>(longStringData);
memChunkPointer->capacity = memChunk.capacity; memChunkPointer->currentSize = memChunk.currentSize;
memChunkPointer->capacity = memChunk.capacity;
// Read the `long string`. // Read the `long string`.
if (!readFixedSizeData(pfd, memChunkPointer->data, memChunkPointer->currentSize, timeout, if (!readFixedSizeData(pfd, memChunkPointer->data, memChunkPointer->currentSize,
isTimeOut, stats, msecs)) timeout, isTimeOut, stats, msecs))
return SBS(new ByteStream(0)); return SBS(new ByteStream(0));
longStrings.push_back(longString); longStrings.push_back(longString);
}
}
catch (std::bad_alloc& exception)
{
logIoError("InetStreamSocket::read: error during read for 'long strings' - 'bad_alloc'", 0);
return SBS(new ByteStream(0));
}
catch (std::exception& exception)
{
std::string errorMsg = "InetStreamSocket::read: error during read for 'long strings' ";
errorMsg += exception.what();
throw runtime_error(errorMsg);
} }
res->setLongStrings(longStrings); res->setLongStrings(longStrings);
return res; return res;
} }