Skip to content

Commit 2f522b4

Browse files
AmirF194sleep-agent
authored andcommitted
fix(cypher): exclude entity-introspection funcs from WITH's bare-node id carry
The bare-node-carry check in with_agg_find_or_create only tested !property && variable, so labels(n)/id(n)/keys(n)/properties(n) aliases (variable set, property NULL, func set) were also tagged with the source node's id. A later alias.property then hit node_prop's stub re-fetch heuristic and silently returned the source node's real property instead of empty for the non-node alias. Adds cypher_issue1111_with_scalar_func_alias_no_node_leak, which fails on the prior code (returns the source node's file_path) and passes with this fix. Addresses DeusData's review on DeusData#1221. Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
1 parent b43bddd commit 2f522b4

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎src/cypher/cypher.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,8 +3780,12 @@ static int with_agg_find_or_create(with_agg_t **aggs, int *agg_cnt, int *agg_cap
37803780
(*aggs)[found].group_vals[ci] = heap_strdup(v);
37813781
/* If this group item is a bare node variable, remember its id so the
37823782
* carried virtual var can re-fetch any property (group_vals holds only
3783-
* the name). */
3784-
if (!wc->items[ci].property && wc->items[ci].variable) {
3783+
* the name). Excludes entity-introspection funcs (labels/id/keys/
3784+
* properties): those project a scalar off the node (via project_item
3785+
* above), not the node itself, so the carried id must not be set or a
3786+
* later alias.property re-fetches the source node's real properties
3787+
* instead of returning empty for the non-node alias. */
3788+
if (!wc->items[ci].func && !wc->items[ci].property && wc->items[ci].variable) {
37853789
cbm_node_t *gn = binding_get(b, wc->items[ci].variable);
37863790
if (gn) {
37873791
(*aggs)[found].group_node_ids[ci] = gn->id;

‎tests/test_cypher.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,31 @@ TEST(cypher_issue1111_with_type_count_group) {
27492749
PASS();
27502750
}
27512751

2752+
/* #1111 follow-up (review from DeusData on #1221): with_agg_find_or_create's
2753+
* bare-node-carry check only tested `!property && variable`, so an entity-
2754+
* introspection alias like `labels(f) AS l` (variable set, property NULL, func
2755+
* set) was ALSO tagged with the source node's id. A later `l.file_path` then
2756+
* hit node_prop's stub re-fetch heuristic (id set, file_path/label both NULL on
2757+
* the virtual stub) and silently returned HandleOrder's real file_path instead
2758+
* of "" for the non-node alias `l`. */
2759+
TEST(cypher_issue1111_with_scalar_func_alias_no_node_leak) {
2760+
cbm_store_t *s = setup_cypher_store();
2761+
cbm_cypher_result_t r = {0};
2762+
int rc = cbm_cypher_execute(s,
2763+
"MATCH (f:Function) WHERE f.name = \"HandleOrder\" "
2764+
"WITH labels(f) AS l, COUNT(*) AS c "
2765+
"RETURN l, l.file_path, c",
2766+
"test", 0, &r);
2767+
ASSERT_EQ(rc, 0);
2768+
ASSERT_EQ(r.row_count, 1);
2769+
ASSERT_STR_EQ(r.rows[0][0], "[\"Function\"]");
2770+
ASSERT_STR_EQ(r.rows[0][1], ""); /* was "handler.go" before the fix */
2771+
ASSERT_STR_EQ(r.rows[0][2], "1");
2772+
cbm_cypher_result_free(&r);
2773+
cbm_store_close(s);
2774+
PASS();
2775+
}
2776+
27522777
TEST(cypher_exec_with_where) {
27532778
cbm_store_t *s = setup_cypher_store();
27542779
cbm_cypher_result_t r = {0};
@@ -3459,6 +3484,7 @@ SUITE(cypher) {
34593484
RUN_TEST(cypher_exec_with_rename);
34603485
RUN_TEST(cypher_exec_with_count);
34613486
RUN_TEST(cypher_issue1111_with_type_count_group);
3487+
RUN_TEST(cypher_issue1111_with_scalar_func_alias_no_node_leak);
34623488
RUN_TEST(cypher_exec_with_node_groupvar_prop);
34633489
RUN_TEST(cypher_exec_with_where);
34643490
RUN_TEST(cypher_exec_with_orderby_limit);

0 commit comments

Comments
 (0)