Skip to content

Commit

Permalink
fix: return an error if reserved value INT32_MIN is used in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Taepper committed Jan 7, 2025
1 parent 10ebbaa commit 042646b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/silo/query_engine/filter_expressions/int_between.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,21 @@ void from_json(const nlohmann::json& json, std::unique_ptr<IntBetween>& filter)
json["column"].is_string(), "The field 'column' in a IntBetween expression must be a string"
);
CHECK_SILO_QUERY(json.contains("from"), "The field 'from' is required in IntBetween expression");
bool value_from_in_allowed_range =
json["from"].is_number_integer() &&
json["from"].get<int32_t>() != storage::column::IntColumn::null();
CHECK_SILO_QUERY(
json["from"].is_null() || json["from"].is_number_integer(),
"The field 'from' in a IntBetween expression must be an int or null"
value_from_in_allowed_range || json["from"].is_null(),
"The field 'from' in an IntBetween expression must be an integer in [-2147483647; "
"2147483647] or null"
);
CHECK_SILO_QUERY(json.contains("to"), "The field 'to' is required in a IntBetween expression");
bool value_to_in_allowed_range = json["to"].is_number_integer() &&
json["to"].get<int32_t>() != storage::column::IntColumn::null();
CHECK_SILO_QUERY(
json["to"].is_null() || json["to"].is_number_integer(),
"The field 'to' in a IntBetween expression must be an int or null"
value_to_in_allowed_range || json["to"].is_null(),
"The field 'to' in an IntBetween expression must be an integer in [-2147483647; 2147483647] "
"or null"
);
const std::string& column_name = json["column"];
std::optional<int32_t> value_from;
Expand Down
7 changes: 5 additions & 2 deletions src/silo/query_engine/filter_expressions/int_equals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ void from_json(const nlohmann::json& json, std::unique_ptr<IntEquals>& filter) {
CHECK_SILO_QUERY(
json.contains("value"), "The field 'value' is required in an IntEquals expression"
);
bool value_in_allowed_range = json["value"].is_number_integer() &&
json["value"].get<int32_t>() != storage::column::IntColumn::null();
CHECK_SILO_QUERY(
json["value"].is_number_integer() || json["value"].is_null(),
"The field 'value' in an IntEquals expression must be an integer or null"
value_in_allowed_range || json["value"].is_null(),
"The field 'value' in an IntEquals expression must be an integer in [-2147483647; "
"2147483647] or null"
);
const std::string& column = json["column"];
const int32_t& value =
Expand Down
29 changes: 28 additions & 1 deletion src/silo/test/int_equals_and_between.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ const QueryTestScenario INT_BETWEEN_WITH_FROM_AND_TO_NULL_SCENARIO = {
{{"primaryKey", "id_3"}, {"int_value", VALUE_ABOVE_FILTER}}}
)
};

const QueryTestScenario INT_EQUALS_WITH_INVALID_VALUE = {
.name = "intEqualsWithInvalidValue",
.query = createIntEqualsQuery("int_value", INT32_MIN),
.expected_error_message =
"The field 'value' in an IntEquals expression must be an integer in [-2147483647; "
"2147483647] or null"
};

const QueryTestScenario INT_BETWEEN_WITH_INVALID_FROM_VALUE = {
.name = "intBetweenWithInvalidFromValue",
.query = createIntBetweenQuery("int_value", INT32_MIN, 1),
.expected_error_message =
"The field 'from' in an IntBetween expression must be an integer in [-2147483647; "
"2147483647] or null"
};

const QueryTestScenario INT_BETWEEN_WITH_INVALID_TO_VALUE = {
.name = "intBetweenWithInvalidToValue",
.query = createIntBetweenQuery("int_value", 0, INT32_MIN),
.expected_error_message =
"The field 'to' in an IntBetween expression must be an integer in [-2147483647; 2147483647] "
"or null"
};
} // namespace

QUERY_TEST(
Expand All @@ -152,6 +176,9 @@ QUERY_TEST(
INT_BETWEEN_WITH_FROM_AND_TO_SCENARIO,
INT_BETWEEN_WITH_FROM_SCENARIO,
INT_BETWEEN_WITH_TO_SCENARIO,
INT_BETWEEN_WITH_FROM_AND_TO_NULL_SCENARIO
INT_BETWEEN_WITH_FROM_AND_TO_NULL_SCENARIO,
INT_EQUALS_WITH_INVALID_VALUE,
INT_BETWEEN_WITH_INVALID_FROM_VALUE,
INT_BETWEEN_WITH_INVALID_TO_VALUE
)
);

0 comments on commit 042646b

Please sign in to comment.