From 0f0209b099aeba4a7da3ceecdbb392b071e1a766 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Sun, 19 Sep 2021 04:11:34 +0200 Subject: [PATCH 1/2] prevent stealing of values from Aql const registers --- arangod/Aql/InputAqlItemRow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arangod/Aql/InputAqlItemRow.cpp b/arangod/Aql/InputAqlItemRow.cpp index 079368eb96af..5c8f9c6434f7 100644 --- a/arangod/Aql/InputAqlItemRow.cpp +++ b/arangod/Aql/InputAqlItemRow.cpp @@ -157,6 +157,11 @@ AqlValue InputAqlItemRow::stealValue(RegisterId registerId) { TRI_ASSERT(registerId.isConstRegister() || registerId < getNumRegisters()); AqlValue const& a = block().getValueReference(_baseIndex, registerId); if (!a.isEmpty() && a.requiresDestruction()) { + if (registerId.isConstRegister()) { + // we cannot steal the value of a const register! + return a.clone(); + } + // Now no one is responsible for AqlValue a block().steal(a); } From 9ac93a5b5cfb9b3cf8057832289d0e92da493cf0 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Sun, 19 Sep 2021 17:19:19 +0200 Subject: [PATCH 2/2] added test --- CHANGELOG | 5 +++ .../shell/shell-query-dbserver-cluster.js | 45 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cd49efcf9c07..35c8e00e355e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ devel ----- +* Prevent stealing of values from AQL const value registers. This fixes an + issue for queries that produce constant results (known at query compile time) + when the queries are executed directly on a DB server in a cluster (which is + not supported, but may happen for troubleshooting). + * Add `--datatype` startup option to arangoimport, in order to hard-code the datatype (null/boolean/number/string) for certain attributes in the CSV/TSV import. For example, given the following input file: diff --git a/tests/js/client/shell/shell-query-dbserver-cluster.js b/tests/js/client/shell/shell-query-dbserver-cluster.js index 5f6e9ceddad3..50b3cc7d1d42 100644 --- a/tests/js/client/shell/shell-query-dbserver-cluster.js +++ b/tests/js/client/shell/shell-query-dbserver-cluster.js @@ -44,7 +44,7 @@ function queriesTestSuite () { 'use strict'; return { - setUp: function() { + setUpAll: function() { arango.reconnect(originalEndpoint, "_system", arango.connectedUser(), ""); db._drop(cn); @@ -56,10 +56,18 @@ function queriesTestSuite () { c.insert(docs); }, - tearDown: function() { + tearDownAll: function() { arango.reconnect(originalEndpoint, "_system", arango.connectedUser(), ""); db._drop(cn); }, + + setUp: function() { + arango.reconnect(originalEndpoint, "_system", arango.connectedUser(), ""); + }, + + tearDown: function() { + arango.reconnect(originalEndpoint, "_system", arango.connectedUser(), ""); + }, // test executing operations on the coordinator testCoordinator: function() { @@ -97,6 +105,39 @@ function queriesTestSuite () { assertEqual(100, totalToArray); assertEqual(100, totalQuery); }, + + // test executing operations on the coordinator, without collection + testCoordinatorNoCollection: function() { + let result = db._query("RETURN [DECODE_REV('_dpq8a-----'), DECODE_REV('_bpq8a-----')]").toArray(); + + assertEqual([ + [ + { "date" : "2022-02-02T16:22:18.368Z", "count" : 0 }, + { "date" : "2021-01-01T00:00:00.000Z", "count" : 0 } + ] + ], result); + }, + + // test executing operations on the DB-Server, without collection + testDBServerNoCollection: function() { + const dbservers = getServers("dbserver"); + assertTrue(dbservers.length > 0, "no dbservers found"); + + dbservers.forEach(function(dbserver, i) { + let id = dbserver.id; + require("console").warn("connecting to dbserver", dbserver.endpoint, id); + arango.reconnect(dbserver.endpoint, "_system", arango.connectedUser(), ""); + + let result = db._query("RETURN [DECODE_REV('_dpq8a-----'), DECODE_REV('_bpq8a-----')]").toArray(); + + assertEqual([ + [ + { "date" : "2022-02-02T16:22:18.368Z", "count" : 0 }, + { "date" : "2021-01-01T00:00:00.000Z", "count" : 0 } + ] + ], result); + }); + }, }; }