-
Notifications
You must be signed in to change notification settings - Fork 231
Error when setting a property to an array containing an invalid type #1898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1898 +/- ##
==========================================
- Coverage 92.61% 86.66% -5.95%
==========================================
Files 239 247 +8
Lines 20300 21588 +1288
==========================================
- Hits 18801 18710 -91
- Misses 1499 2878 +1379
Continue to review full report at Codecov.
|
tests/flow/test_entity_update.py
Outdated
# Skip this test if running under Valgrind, as it causes a memory leak. | ||
if Env().envRunner.debugger is not None: | ||
Env().skip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we leaking here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had been; I rewrote the validation such that it no longer leaks.
As with many other run-time validations, it is still possible to cause leaks when jumping to the exception handler. For example, this query would leak:
WITH {k: 'v'} AS map MATCH (a) SET a.v = [map]
(In this case, map
will leak due to its allocation at https://github.com/RedisGraph/RedisGraph/blob/master/src/execution_plan/ops/op_update.c#L75)
I don't believe these leaks can be entirely plugged without a change like SIValue reference counting.
tests/flow/test_entity_update.py
Outdated
graph.query("MATCH (a) SET a = {v: ['str', [1, NULL]]}") | ||
self.env.assertTrue(False) | ||
except ResponseError as e: | ||
self.env.assertContains("Property values can only be of primitive types or arrays of primitive types", str(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test for all cases where an array contains a restricted type:
- map
- node
- edge
- null
48545db
to
42bd377
Compare
static bool _ValidateArrayProperty(SIValue arr) { | ||
ASSERT(SI_TYPE(arr) == T_ARRAY); | ||
|
||
uint array_len = SIArray_Length(arr); | ||
for(uint i = 0; i < array_len; i++) { | ||
SIValue elem = SIArray_Get(arr, i); | ||
// each element must be a primitive or an array | ||
if(!(SI_TYPE(elem) & SI_VALID_PROPERTY_VALUE)) return false; | ||
|
||
// recursively check nested arrays | ||
if(SI_TYPE(elem) == T_ARRAY) return _ValidateArrayProperty(elem); | ||
} | ||
|
||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be cleaner if we introduce bool containType(SIArray arr, SIType t)
to SIArray,
this way we can call this function using bitwise or to describe all forbidden types. also it seems like we might have missed cases where we set a property to an invalid value upon entity creation.
2d24cd4
to
9ab99e9
Compare
if(SI_TYPE(elem) & t) return true; | ||
|
||
// recursively check nested arrays | ||
if(SI_TYPE(elem) == T_ARRAY) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness, I think we should also recursively test Map
data type
add unit-test for this function as part of test_value.cpp
or introduce test_array.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite follow the first part of this request. Map
types cannot be used as property values, so the logic in this PR disallows them in the same way that a node or edge value would be disallowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although you're looking at this from a specific context.
@@ -244,6 +245,21 @@ PendingProperties *ConvertPropertyMap(Record r, PropertyMap *map, bool fail_on_n | |||
ErrorCtx_RaiseRuntimeException("Cannot merge node using null property value"); | |||
} | |||
} | |||
|
|||
// emit an error and exit if we're trying to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've notice converted
is leaking in-case of an error, consider switching to a two loops logic:
1. validate expressions (can through an error)
2. allocate
3. assign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can restructure the function like that, but I don't think it will fix any existing leaks. In the event of an error on property N, we call PendingPropertiesFree(converted)
and free the previously computed property values 0..N.
// emit an error and exit if we're trying to add | ||
// an array containing an invalid type | ||
if(SI_TYPE(val) == T_ARRAY) { | ||
SIType invalid_properties = ~SI_VALID_PROPERTY_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
tests/flow/test_graph_create.py
Outdated
@@ -102,3 +102,18 @@ def test06_create_project_volatile_value(self): | |||
|
|||
self.env.assertEquals(result.nodes_created, 1) | |||
self.env.assertEquals(result.result_set, expected_result) | |||
|
|||
# Fail when a property is a complex type nested within an array type | |||
def test13_invalid_complex_type_in_array(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename function name, test14...
or combine with test13_invalid_complex_type_in_array
ASSERT_TRUE(contains_double); | ||
|
||
bool contains_string = SIArray_ContainsType(arr, T_STRING); | ||
ASSERT_FALSE(contains_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test which checks the combination of types: SIArray_ContainsType(arr, t0&t1)
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
* Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Aliases in WITH...ORDER BY must be valid references (#1897) * Ensure aliases in the ORDER BY segment of a WITH clause are valid references * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * increase code coverage (#1919) * clean unused files * delete v5 decoder * test decoders * fix build * delete unused functions * add deleted nodes and edges to rdb * fix unused function * address review * Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Storing test artifacts for CI runs (#1906) * Storing test artifacts * PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * sync matrices on parent process before fork (#1931) * sync matrices on parent process before fork * formatting * Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> Co-authored-by: Jeffrey Lovitz <jeffrey.lovitz@gmail.com> Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> Co-authored-by: Chayim <chayim@users.noreply.github.com>
…1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
* Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Aliases in WITH...ORDER BY must be valid references (#1897) * Ensure aliases in the ORDER BY segment of a WITH clause are valid references * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * increase code coverage (#1919) * clean unused files * delete v5 decoder * test decoders * fix build * delete unused functions * add deleted nodes and edges to rdb * fix unused function * address review * Storing test artifacts for CI runs (#1906) * Storing test artifacts * PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * sync matrices on parent process before fork (#1931) * sync matrices on parent process before fork * formatting * fix tests * fix bgsave * Error when setting a property to an array containing an invalid type (#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * Aliases in WITH...ORDER BY must be valid references (#1897) * Ensure aliases in the ORDER BY segment of a WITH clause are valid references * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * increase code coverage (#1919) * clean unused files * delete v5 decoder * test decoders * fix build * delete unused functions * add deleted nodes and edges to rdb * fix unused function * address review * Storing test artifacts for CI runs (#1906) * Storing test artifacts * PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> * sync matrices on parent process before fork (#1931) * sync matrices on parent process before fork * formatting * fix tests * fix bgsave * fix timeout test Co-authored-by: Jeffrey Lovitz <jeffrey.lovitz@gmail.com> Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com> Co-authored-by: Chayim <chayim@users.noreply.github.com>
…edisGraph#1898) * Emit error when setting a property to an array containing an invalid type * Address PR comments * Address PR comments * Address PR comments * Address PR comments Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
Previously, when saving an array as a property value, we did not introspect on the arrays contents to make sure that all elements were non-NULL primitive data types or arrays thereof. As such, invalid formulations such as:
Were accepted, and would only crash in serialization.
This PR adds recursive array-checking to make sure that only valid data types are saved within property arrays.
Resolves #1861