From 54e599161d4d4a70e36dcaa1065311198aa58130 Mon Sep 17 00:00:00 2001 From: Alexander Gololobov <440544+davenger@users.noreply.github.com> Date: Sat, 18 Jun 2022 00:16:45 +0200 Subject: [PATCH] Check row size to avoid out of bounds access --- src/Processors/Transforms/PostgreSQLSource.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Processors/Transforms/PostgreSQLSource.cpp b/src/Processors/Transforms/PostgreSQLSource.cpp index 6926ac26bbc..77c2fc41aa1 100644 --- a/src/Processors/Transforms/PostgreSQLSource.cpp +++ b/src/Processors/Transforms/PostgreSQLSource.cpp @@ -1,4 +1,5 @@ #include "PostgreSQLSource.h" +#include "Common/Exception.h" #if USE_LIBPQXX #include @@ -22,6 +23,10 @@ namespace DB { +namespace ErrorCodes +{ + extern const int TOO_MANY_COLUMNS; +} template PostgreSQLSource::PostgreSQLSource( @@ -123,6 +128,11 @@ Chunk PostgreSQLSource::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);