Skip to content

Commit

Permalink
vendor: Update vendored sources to duckdb/duckdb@2edfde3 (#973)
Browse files Browse the repository at this point in the history
DuckFuzz Fix on Null parameters for both read_csv and sniff_csv (duckdb/duckdb#15565)

Co-authored-by: krlmlr <[email protected]>
  • Loading branch information
github-actions[bot] and krlmlr authored Jan 7, 2025
1 parent 2d5e205 commit bafb8c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace duckdb {

CSVReaderOptions::CSVReaderOptions(CSVOption<char> single_byte_delimiter,
CSVReaderOptions::CSVReaderOptions(const CSVOption<char> single_byte_delimiter,
const CSVOption<string> &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;
Expand All @@ -32,7 +32,9 @@ static bool ParseBoolean(const vector<Value> &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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -543,6 +548,13 @@ void CSVReaderOptions::Verify() {
}
}

bool GetBooleanValue(const pair<const string, Value> &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<string, string> ordered_user_defined_parameters;
for (auto &kv : in) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/duckdb/src/function/table/sniff_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ static unique_ptr<GlobalTableFunctionState> CSVSniffInitGlobal(ClientContext &co
static unique_ptr<FunctionData> CSVSniffBind(ClientContext &context, TableFunctionBindInput &input,
vector<LogicalType> &return_types, vector<string> &names) {
auto result = make_uniq<CSVSniffFunctionData>();
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<bool>()) {
throw InvalidInputException("sniff_csv function does not accept auto_detect variable set to false");
}
Expand Down Expand Up @@ -169,7 +175,7 @@ static void CSVSniffFunction(ClientContext &context, TableFunctionInput &data_p,
// 6. Skip Rows
output.SetValue(5, 0, Value::UINTEGER(NumericCast<uint32_t>(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<Struct<Column-Name:Types>> {'col1': 'INTEGER', 'col2': 'VARCHAR'}
vector<Value> values;
Expand Down
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down

0 comments on commit bafb8c7

Please sign in to comment.