From bafb8c7ea03b3c811477f9180ca3f0f6ec5a3de9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:23:04 +0000 Subject: [PATCH] vendor: Update vendored sources to duckdb/duckdb@2edfde3071cdc3ccc6047773e8229fb80238443d (#973) DuckFuzz Fix on Null parameters for both read_csv and sniff_csv (duckdb/duckdb#15565) Co-authored-by: krlmlr --- .../csv_scanner/util/csv_reader_options.cpp | 27 +++++++++++++------ src/duckdb/src/function/table/sniff_csv.cpp | 8 +++++- .../function/table/version/pragma_version.cpp | 6 ++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp b/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp index 2b05b242b..1a2ee65da 100644 --- a/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp +++ b/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp @@ -8,11 +8,11 @@ namespace duckdb { -CSVReaderOptions::CSVReaderOptions(CSVOption single_byte_delimiter, +CSVReaderOptions::CSVReaderOptions(const CSVOption single_byte_delimiter, const CSVOption &multi_byte_delimiter) { if (multi_byte_delimiter.GetValue().empty()) { - char single_byte_value = single_byte_delimiter.GetValue(); - string value(1, single_byte_value); + const char single_byte_value = single_byte_delimiter.GetValue(); + const string value(1, single_byte_value); dialect_options.state_machine_options.delimiter = value; } else { dialect_options.state_machine_options.delimiter = multi_byte_delimiter; @@ -32,7 +32,9 @@ static bool ParseBoolean(const vector &set, const string &loption) { } static bool ParseBoolean(const Value &value, const string &loption) { - + if (value.IsNull()) { + throw BinderException("\"%s\" expects a non-null boolean value (e.g. TRUE or 1)", loption); + } if (value.type().id() == LogicalTypeId::LIST) { auto &children = ListValue::GetChildren(value); return ParseBoolean(children, loption); @@ -62,6 +64,9 @@ static string ParseString(const Value &value, const string &loption) { } static int64_t ParseInteger(const Value &value, const string &loption) { + if (value.IsNull()) { + throw BinderException("\"%s\" expects a non-null integer value", loption); + } if (value.type().id() == LogicalTypeId::LIST) { auto &children = ListValue::GetChildren(value); if (children.size() != 1) { @@ -224,7 +229,7 @@ void CSVReaderOptions::SetReadOption(const string &loption, const Value &value, if (loption == "auto_detect") { auto_detect = ParseBoolean(value, loption); } else if (loption == "sample_size") { - auto sample_size_option = ParseInteger(value, loption); + const auto sample_size_option = ParseInteger(value, loption); if (sample_size_option < 1 && sample_size_option != -1) { throw BinderException("Unsupported parameter for SAMPLE_SIZE: cannot be smaller than 1"); } @@ -543,6 +548,13 @@ void CSVReaderOptions::Verify() { } } +bool GetBooleanValue(const pair &option) { + if (option.second.IsNull()) { + throw BinderException("read_csv %s cannot be NULL", option.first); + } + return BooleanValue::Get(option.second); +} + void CSVReaderOptions::FromNamedParameters(const named_parameter_map_t &in, ClientContext &context) { map ordered_user_defined_parameters; for (auto &kv : in) { @@ -672,9 +684,9 @@ void CSVReaderOptions::FromNamedParameters(const named_parameter_map_t &in, Clie sql_type_list.push_back(std::move(def_type)); } } else if (loption == "all_varchar") { - all_varchar = BooleanValue::Get(kv.second); + all_varchar = GetBooleanValue(kv); } else if (loption == "normalize_names") { - normalize_names = BooleanValue::Get(kv.second); + normalize_names = GetBooleanValue(kv); } else { SetReadOption(loption, kv.second, name_list); } @@ -686,7 +698,6 @@ void CSVReaderOptions::FromNamedParameters(const named_parameter_map_t &in, Clie user_defined_parameters.erase(user_defined_parameters.size() - 2); } } - //! This function is used to remember options set by the sniffer, for use in ReadCSVRelation void CSVReaderOptions::ToNamedParameters(named_parameter_map_t &named_params) const { auto &delimiter = dialect_options.state_machine_options.delimiter; diff --git a/src/duckdb/src/function/table/sniff_csv.cpp b/src/duckdb/src/function/table/sniff_csv.cpp index c278dd723..5c72aabb9 100644 --- a/src/duckdb/src/function/table/sniff_csv.cpp +++ b/src/duckdb/src/function/table/sniff_csv.cpp @@ -38,9 +38,15 @@ static unique_ptr CSVSniffInitGlobal(ClientContext &co static unique_ptr CSVSniffBind(ClientContext &context, TableFunctionBindInput &input, vector &return_types, vector &names) { auto result = make_uniq(); + if (input.inputs[0].IsNull()) { + throw BinderException("sniff_csv cannot take NULL as a file path parameter"); + } result->path = input.inputs[0].ToString(); auto it = input.named_parameters.find("auto_detect"); if (it != input.named_parameters.end()) { + if (it->second.IsNull()) { + throw BinderException("\"%s\" expects a non-null boolean value (e.g. TRUE or 1)", it->first); + } if (!it->second.GetValue()) { throw InvalidInputException("sniff_csv function does not accept auto_detect variable set to false"); } @@ -169,7 +175,7 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p, // 6. Skip Rows output.SetValue(5, 0, Value::UINTEGER(NumericCast(sniffer_options.dialect_options.skip_rows.GetValue()))); // 7. Has Header - auto has_header = Value::BOOLEAN(sniffer_options.dialect_options.header.GetValue()).ToString(); + auto has_header = Value::BOOLEAN(sniffer_options.dialect_options.header.GetValue()); output.SetValue(6, 0, has_header); // 8. List> {'col1': 'INTEGER', 'col2': 'VARCHAR'} vector values; diff --git a/src/duckdb/src/function/table/version/pragma_version.cpp b/src/duckdb/src/function/table/version/pragma_version.cpp index 2316757b3..77e744b6b 100644 --- a/src/duckdb/src/function/table/version/pragma_version.cpp +++ b/src/duckdb/src/function/table/version/pragma_version.cpp @@ -1,5 +1,5 @@ #ifndef DUCKDB_PATCH_VERSION -#define DUCKDB_PATCH_VERSION "4-dev4102" +#define DUCKDB_PATCH_VERSION "4-dev4106" #endif #ifndef DUCKDB_MINOR_VERSION #define DUCKDB_MINOR_VERSION 1 @@ -8,10 +8,10 @@ #define DUCKDB_MAJOR_VERSION 1 #endif #ifndef DUCKDB_VERSION -#define DUCKDB_VERSION "v1.1.4-dev4102" +#define DUCKDB_VERSION "v1.1.4-dev4106" #endif #ifndef DUCKDB_SOURCE_ID -#define DUCKDB_SOURCE_ID "3c0db29b2b" +#define DUCKDB_SOURCE_ID "2edfde3071" #endif #include "duckdb/function/table/system_functions.hpp" #include "duckdb/main/database.hpp"