Check row size to avoid out of bounds access

This commit is contained in:
Alexander Gololobov 2022-06-18 00:16:45 +02:00
parent f72e509b3b
commit 54e599161d

View File

@ -1,4 +1,5 @@
#include "PostgreSQLSource.h"
#include "Common/Exception.h"
#if USE_LIBPQXX
#include <Columns/ColumnNullable.h>
@ -22,6 +23,10 @@
namespace DB
{
namespace ErrorCodes
{
extern const int TOO_MANY_COLUMNS;
}
template<typename T>
PostgreSQLSource<T>::PostgreSQLSource(
@ -123,6 +128,11 @@ Chunk PostgreSQLSource<T>::generate()
if (!row)
break;
if (row->size() > description.sample_block.columns())
throw Exception(ErrorCodes::TOO_MANY_COLUMNS,
"Row has too many columns: {}, expected structure: {}",
row->size(), description.sample_block.dumpStructure());
for (const auto idx : collections::range(0, row->size()))
{
const auto & sample = description.sample_block.getByPosition(idx);