Merge pull request #38190 from ClickHouse/fix_36123

Check row size to avoid out of bounds access in PostgreSQLSource
This commit is contained in:
alesapin 2022-06-18 14:18:35 +02:00 committed by GitHub
commit 1d7cf28cab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);