Skip to content

Commit 8182025

Browse files
authored
Merge branch 'main' into fix/issue-2265-unresolved-call-coverage
2 parents 3421848 + 8530c8c commit 8182025

27 files changed

Lines changed: 1519 additions & 106 deletions

‎install.ps1‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,28 @@ try {
277277

278278
# Validate the zip namespace before extraction. Windows paths are
279279
# case-insensitive, so two entries that differ only in case are ambiguous and
280-
# must never be allowed to overwrite each other. The official five entries are
280+
# must never be allowed to overwrite each other. The official four entries are
281281
# required at the archive root with their exact release names.
282+
#
283+
# Two failure classes are reported differently (both still exit 1; nothing is
284+
# relaxed). An unsafe entry path or a duplicate/case-conflicting entry is a
285+
# hostile archive shape. A well-formed archive whose root file SET differs from
286+
# $WindowsArchiveNames already passed checksum verification above, so it is
287+
# the published artifact for $BaseUrl -- the usual cause is this script being
288+
# newer or older than that release (e.g. install.ps1 run from main ahead of
289+
# the latest release, #1218). Calling that "unsafe" sends the user hunting for
290+
# tampering that is not there. Every entry is screened for the hostile class
291+
# BEFORE any layout verdict, so a bad path can never hide behind a layout
292+
# message just because an unexpected entry happened to come first.
293+
$LayoutMismatch = $false
282294
try {
283295
Add-Type -AssemblyName System.IO.Compression.FileSystem
284296
$zip = [System.IO.Compression.ZipFile]::OpenRead("$TmpDir\$Archive")
285297
try {
286298
$seen = New-Object 'System.Collections.Generic.HashSet[string]' ([System.StringComparer]::OrdinalIgnoreCase)
287299
$archiveCounts = @{}
288300
foreach ($archiveName in $WindowsArchiveNames) { $archiveCounts[$archiveName] = 0 }
301+
$layoutProblem = $null
289302
foreach ($entry in $zip.Entries) {
290303
$entryName = $entry.FullName.Replace('\', '/')
291304
$isDirectory = $entryName.EndsWith('/')
@@ -304,10 +317,16 @@ try {
304317
throw "duplicate or case-conflicting zip entry: $($entry.FullName)"
305318
}
306319
if (-not ($WindowsArchiveNames -ccontains $entryName) -or $isDirectory) {
307-
throw "archive contains an unexpected root entry: $($entry.FullName)"
320+
if ($null -eq $layoutProblem) {
321+
$layoutProblem = "archive contains an unexpected root entry: $($entry.FullName)"
322+
}
323+
continue
308324
}
309325
$archiveCounts[$entryName] = $archiveCounts[$entryName] + 1
310326
}
327+
# Every entry passed the hostile-shape checks; only now judge the layout.
328+
$LayoutMismatch = $true
329+
if ($null -ne $layoutProblem) { throw $layoutProblem }
311330
foreach ($archiveName in $WindowsArchiveNames) {
312331
if ($archiveCounts[$archiveName] -ne 1) {
313332
throw "archive must contain exactly one $archiveName"
@@ -316,11 +335,21 @@ try {
316335
if ($seen.Count -ne $WindowsArchiveNames.Count) {
317336
throw "archive does not match the exact Windows release allowlist"
318337
}
338+
$LayoutMismatch = $false
319339
} finally {
320340
$zip.Dispose()
321341
}
322342
} catch {
323-
Write-Host "error: unsafe or incomplete release archive: $_" -ForegroundColor Red
343+
if ($LayoutMismatch) {
344+
Write-Host "error: release archive layout does not match this installer: $_" -ForegroundColor Red
345+
Write-Host " The archive matched the checksum published with it at $BaseUrl, so it is"
346+
Write-Host " the genuine release artifact, built for a different installer version."
347+
Write-Host " This installer expects: $($WindowsArchiveNames -join ', ')"
348+
Write-Host " Fix: run the install.ps1 shipped inside that same release archive, or"
349+
Write-Host " re-run this script after the next release is published."
350+
} else {
351+
Write-Host "error: unsafe release archive: $_" -ForegroundColor Red
352+
}
324353
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
325354
exit 1
326355
}

‎scripts/embed-frontend.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ for file in "${FILES[@]}"; do
7272
if $IS_LINUX; then
7373
# Linux: ld -r -b binary (zero bloat, ELF only)
7474
abs_obj="$(cd "$(dirname "$0")/.." && pwd)/$obj"
75-
(cd "$DIST_DIR" && ld -r -b binary -o "$abs_obj" "$rel")
75+
(cd "$DIST_DIR" && "${LD:-ld}" -r -b binary -o "$abs_obj" "$rel")
7676
else
7777
# macOS/Windows/MSYS2: generate C byte array + cc (no xxd dependency)
7878
local_c="$OUTPUT_DIR/embed_${mangled}.c"

‎src/cypher/cypher.c‎

Lines changed: 148 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,8 @@ static void expr_free(cbm_expr_t *e) {
791791
safe_str_free(&cur->cond.op);
792792
safe_str_free(&cur->cond.value);
793793
safe_str_free(&cur->cond.coalesce_default);
794+
safe_str_free(&cur->cond.rhs_variable);
795+
safe_str_free(&cur->cond.rhs_property);
794796
for (int i = 0; i < cur->cond.in_value_count; i++) {
795797
safe_str_free(&cur->cond.in_values[i]);
796798
}
@@ -1081,9 +1083,49 @@ static cbm_expr_t *parse_exists_predicate(parser_t *p, bool negated) {
10811083
return expr_leaf(c);
10821084
}
10831085

1086+
/* Free what a condition parser owns when it gives up mid-condition. */
1087+
static void cond_parse_fail_free(cbm_condition_t *c) {
1088+
cond_func_fields_free(c);
1089+
safe_str_free(&c->variable);
1090+
safe_str_free(&c->property);
1091+
safe_str_free(&c->op);
1092+
safe_str_free(&c->coalesce_default);
1093+
safe_str_free(&c->rhs_variable);
1094+
safe_str_free(&c->rhs_property);
1095+
}
1096+
1097+
enum { COND_RHS_REF = 1 };
1098+
1099+
/* RHS operand that names a row value instead of a literal: var.prop, or a bare
1100+
* alias such as a WITH projection (#2591). Returns COND_RHS_REF when one was
1101+
* parsed, 0 when the next token is not one, CBM_NOT_FOUND with p->error set
1102+
* when it is malformed or a function call. */
1103+
static int parse_condition_rhs_ref(parser_t *p, cbm_condition_t *c) {
1104+
if (p->pos + SKIP_ONE < p->count && p->tokens[p->pos + SKIP_ONE].type == TOK_LPAREN) {
1105+
snprintf(p->error, sizeof(p->error),
1106+
"unsupported function '%s' on the right side of a WHERE comparison "
1107+
"(only literals and var.prop are supported)",
1108+
peek(p)->text);
1109+
return CBM_NOT_FOUND;
1110+
}
1111+
if (!check(p, TOK_IDENT)) {
1112+
return 0;
1113+
}
1114+
c->rhs_variable = heap_strdup(advance(p)->text);
1115+
if (match(p, TOK_DOT)) {
1116+
const cbm_token_t *prop = expect(p, TOK_IDENT);
1117+
if (!prop) {
1118+
return CBM_NOT_FOUND;
1119+
}
1120+
c->rhs_property = heap_strdup(prop->text);
1121+
}
1122+
return COND_RHS_REF;
1123+
}
1124+
10841125
/* Parse the operator + value tail shared by every condition subject
10851126
* (var[.prop] and multi-arg functions like coalesce(...)): IS [NOT] NULL,
1086-
* IN [...], or a comparison operator with a literal value. */
1127+
* IN [...], or a comparison operator with a literal value or a property
1128+
* reference (a.x = b.y). */
10871129
static cbm_expr_t *parse_condition_op(parser_t *p, cbm_condition_t *c) {
10881130
/* IS NULL / IS NOT NULL */
10891131
if (check(p, TOK_IS)) {
@@ -1111,10 +1153,7 @@ static cbm_expr_t *parse_condition_op(parser_t *p, cbm_condition_t *c) {
11111153
c->op = parse_comparison_op(p);
11121154
if (!c->op) {
11131155
snprintf(p->error, sizeof(p->error), "unexpected operator at pos %d", peek(p)->pos);
1114-
cond_func_fields_free(c);
1115-
safe_str_free(&c->variable);
1116-
safe_str_free(&c->property);
1117-
safe_str_free(&c->coalesce_default);
1156+
cond_parse_fail_free(c);
11181157
return NULL;
11191158
}
11201159

@@ -1127,13 +1166,11 @@ static cbm_expr_t *parse_condition_op(parser_t *p, cbm_condition_t *c) {
11271166
} else if (check(p, TOK_FALSE)) {
11281167
advance(p);
11291168
c->value = heap_strdup("false");
1130-
} else {
1131-
snprintf(p->error, sizeof(p->error), "expected value at pos %d", peek(p)->pos);
1132-
cond_func_fields_free(c);
1133-
safe_str_free(&c->variable);
1134-
safe_str_free(&c->property);
1135-
safe_str_free(&c->op);
1136-
safe_str_free(&c->coalesce_default);
1169+
} else if (parse_condition_rhs_ref(p, c) <= 0) {
1170+
if (!p->error[0]) {
1171+
snprintf(p->error, sizeof(p->error), "expected value at pos %d", peek(p)->pos);
1172+
}
1173+
cond_parse_fail_free(c);
11371174
return NULL;
11381175
}
11391176

@@ -2227,6 +2264,8 @@ static void free_where(cbm_where_clause_t *w) {
22272264
free(w->conditions[i].in_values);
22282265
safe_str_free(&w->conditions[i].func);
22292266
func_args_free(w->conditions[i].args, w->conditions[i].arg_count);
2267+
safe_str_free(&w->conditions[i].rhs_variable);
2268+
safe_str_free(&w->conditions[i].rhs_property);
22302269
}
22312270
free(w->conditions);
22322271
safe_str_free(&w->op);
@@ -2732,6 +2771,59 @@ static bool eval_comparison_op(const char *op, const char *actual, const char *e
27322771
return false;
27332772
}
27342773

2774+
enum { EXISTS_DIR_OUT = 0, EXISTS_DIR_IN = 1 };
2775+
2776+
/* EXISTS { (var)-[:TYPE]->() }: does the bound node have any edge of the
2777+
* given type in the requested direction? (dir 0=out, 1=in, 2=any) */
2778+
static bool eval_exists_condition(const cbm_condition_t *c, binding_t *b) {
2779+
cbm_node_t *n = binding_get(b, c->variable);
2780+
bool result = false;
2781+
if (n && b->store) {
2782+
cbm_edge_t *edges = NULL;
2783+
int cnt = 0;
2784+
if (c->exists_dir != EXISTS_DIR_IN) { /* outbound or any */
2785+
if (c->value) {
2786+
cbm_store_find_edges_by_source_type(b->store, n->id, c->value, &edges, &cnt);
2787+
} else {
2788+
cbm_store_find_edges_by_source(b->store, n->id, &edges, &cnt);
2789+
}
2790+
result = cnt > 0;
2791+
cbm_store_free_edges(edges, cnt);
2792+
}
2793+
if (!result && c->exists_dir != EXISTS_DIR_OUT) { /* inbound or any */
2794+
edges = NULL;
2795+
cnt = 0;
2796+
if (c->value) {
2797+
cbm_store_find_edges_by_target_type(b->store, n->id, c->value, &edges, &cnt);
2798+
} else {
2799+
cbm_store_find_edges_by_target(b->store, n->id, &edges, &cnt);
2800+
}
2801+
result = cnt > 0;
2802+
cbm_store_free_edges(edges, cnt);
2803+
}
2804+
}
2805+
return c->negated ? !result : result;
2806+
}
2807+
2808+
/* a.x <op> b.y (#2591): the RHS operand is read from the same row. An unbound
2809+
* RHS alias does not filter, like an unbound LHS. A missing (empty) property
2810+
* on either side is NULL and the comparison is false, so two nodes that both
2811+
* lack a property do not compare equal. */
2812+
static bool eval_property_comparison(const cbm_condition_t *c, const char *actual, binding_t *b) {
2813+
cbm_condition_t rhs = {0};
2814+
rhs.variable = c->rhs_variable;
2815+
rhs.property = c->rhs_property;
2816+
const char *expected = resolve_condition_value(&rhs, b);
2817+
if (!expected) {
2818+
return true;
2819+
}
2820+
if (actual[0] == '\0' || expected[0] == '\0') {
2821+
return false;
2822+
}
2823+
bool result = eval_comparison_op(c->op, actual, expected);
2824+
return c->negated ? !result : result;
2825+
}
2826+
27352827
/* Evaluate a WHERE condition against a binding */
27362828
static bool eval_condition(const cbm_condition_t *c, binding_t *b) {
27372829
/* Label test: WHERE n:Label (#241) — compare the bound node's label
@@ -2742,36 +2834,8 @@ static bool eval_condition(const cbm_condition_t *c, binding_t *b) {
27422834
return c->negated ? !result : result;
27432835
}
27442836

2745-
/* EXISTS { (var)-[:TYPE]->() }: does the bound node have any edge of the
2746-
* given type in the requested direction? (dir 0=out, 1=in, 2=any) */
27472837
if (strcmp(c->op, "EXISTS") == 0) {
2748-
cbm_node_t *n = binding_get(b, c->variable);
2749-
bool result = false;
2750-
if (n && b->store) {
2751-
cbm_edge_t *edges = NULL;
2752-
int cnt = 0;
2753-
if (c->exists_dir != 1) { /* outbound or any */
2754-
if (c->value) {
2755-
cbm_store_find_edges_by_source_type(b->store, n->id, c->value, &edges, &cnt);
2756-
} else {
2757-
cbm_store_find_edges_by_source(b->store, n->id, &edges, &cnt);
2758-
}
2759-
result = cnt > 0;
2760-
cbm_store_free_edges(edges, cnt);
2761-
}
2762-
if (!result && c->exists_dir != 0) { /* inbound or any */
2763-
edges = NULL;
2764-
cnt = 0;
2765-
if (c->value) {
2766-
cbm_store_find_edges_by_target_type(b->store, n->id, c->value, &edges, &cnt);
2767-
} else {
2768-
cbm_store_find_edges_by_target(b->store, n->id, &edges, &cnt);
2769-
}
2770-
result = cnt > 0;
2771-
cbm_store_free_edges(edges, cnt);
2772-
}
2773-
}
2774-
return c->negated ? !result : result;
2838+
return eval_exists_condition(c, b);
27752839
}
27762840

27772841
const char *actual = resolve_condition_value(c, b);
@@ -2808,6 +2872,9 @@ static bool eval_condition(const cbm_condition_t *c, binding_t *b) {
28082872
return c->negated ? !result : result;
28092873
}
28102874

2875+
if (c->rhs_variable) {
2876+
return eval_property_comparison(c, actual, b);
2877+
}
28112878
result = eval_comparison_op(c->op, actual, c->value);
28122879
return c->negated ? !result : result;
28132880
}
@@ -2904,11 +2971,12 @@ static bool partial_alias_unbound(binding_t *b, const char *alias) {
29042971
}
29052972

29062973
/* A condition is UNKNOWN while any alias it reads is not bound yet: its own
2907-
* variable, and every function argument's -- a func condition is filed under
2908-
* its first argument's alias, so the b in coalesce(a.x, b.name) is only seen
2909-
* here. A literal-only LHS has nothing to wait for. */
2974+
* variable, the RHS of a property comparison (the b in a.x = b.y), and every
2975+
* function argument's -- a func condition is filed under its first argument's
2976+
* alias, so the b in coalesce(a.x, b.name) is only seen here. A literal-only
2977+
* LHS has nothing to wait for. */
29102978
static cyp_partial_t eval_condition_partial(const cbm_condition_t *c, binding_t *b) {
2911-
if (partial_alias_unbound(b, c->variable)) {
2979+
if (partial_alias_unbound(b, c->variable) || partial_alias_unbound(b, c->rhs_variable)) {
29122980
return CYP_PARTIAL_UNKNOWN;
29132981
}
29142982
for (int i = 0; i < c->arg_count; i++) {
@@ -5370,6 +5438,34 @@ static void ret_agg_emit_row(cbm_return_clause_t *ret, ret_agg_entry_t *agg, res
53705438
rb_add_row(rb, row);
53715439
}
53725440

5441+
/* True when every RETURN item is an aggregate, so the whole input is one group. */
5442+
static bool ret_agg_is_ungrouped(const cbm_return_clause_t *ret) {
5443+
for (int ci = 0; ci < ret->count; ci++) {
5444+
if (!is_aggregate_func(ret->items[ci].func)) {
5445+
return false;
5446+
}
5447+
}
5448+
return true;
5449+
}
5450+
5451+
/* The one row an ungrouped aggregation answers when no binding reached it
5452+
* (#2742): count and sum are 0, collect is an empty list, and avg/min/max have
5453+
* no value, rendered as "" like any other null. */
5454+
static void ret_agg_emit_empty_row(cbm_return_clause_t *ret, result_builder_t *rb) {
5455+
const char *row[CBM_SZ_32];
5456+
for (int ci = 0; ci < ret->count && ci < CBM_SZ_32; ci++) {
5457+
const char *func = ret->items[ci].func;
5458+
if (strcmp(func, "COUNT") == 0 || strcmp(func, "SUM") == 0) {
5459+
row[ci] = "0";
5460+
} else if (strcmp(func, "COLLECT") == 0) {
5461+
row[ci] = "[]";
5462+
} else {
5463+
row[ci] = "";
5464+
}
5465+
}
5466+
rb_add_row(rb, row);
5467+
}
5468+
53735469
static void ret_sink_feed_agg(ret_sink_t *s, binding_t *bindings, int bind_count) {
53745470
cbm_return_clause_t *ret = s->ret;
53755471
for (int bi = 0; bi < bind_count && !s->done; bi++) {
@@ -5586,6 +5682,11 @@ static void ret_sink_finish(ret_sink_t *s) {
55865682
for (int a = 0; a < s->agg_count; a++) {
55875683
ret_agg_emit_row(ret, &s->aggs[a], rb);
55885684
}
5685+
/* Without grouping keys the input is a single group even when it is
5686+
* empty; a grouped aggregation over no rows has no group to report. */
5687+
if (s->agg_count == 0 && ret_agg_is_ungrouped(ret)) {
5688+
ret_agg_emit_empty_row(ret, rb);
5689+
}
55895690
}
55905691
ret_sink_free(s);
55915692

@@ -5885,7 +5986,8 @@ static int cypher_cond_selectivity(const cbm_condition_t *c, const char *var) {
58855986
if (!c || !c->variable || !var || strcmp(c->variable, var) != 0 || c->negated) {
58865987
return 0;
58875988
}
5888-
if (!c->op || strcmp(c->op, "=") != 0 || !c->property) {
5989+
/* a.x = b.y pins no value on either alias, so it seeds nothing. */
5990+
if (!c->op || strcmp(c->op, "=") != 0 || !c->property || c->rhs_variable) {
58895991
return 0;
58905992
}
58915993
return (strcmp(c->property, "name") == 0 || strcmp(c->property, "qualified_name") == 0) ? 3 : 2;

‎src/cypher/cypher.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ typedef struct {
210210
const char *func;
211211
cbm_func_arg_t *args;
212212
int arg_count;
213+
/* Property reference on the RHS, e.g. a.file_path = b.file_path (#2591).
214+
* When rhs_variable is set the comparison reads its operand from the row
215+
* instead of `value`; rhs_property NULL = bare alias. */
216+
const char *rhs_variable;
217+
const char *rhs_property;
213218
} cbm_condition_t;
214219

215220
/* Expression tree for WHERE clause */

0 commit comments

Comments
 (0)