Skip to content

prevent stealing of values from Aql const registers #14798

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

Merged
merged 3 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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).

* Fixed BTS-562: reduce-extraction-to-projection optimization returns null for
one attribute if nested attributes are named the same.

Expand Down
5 changes: 5 additions & 0 deletions arangod/Aql/InputAqlItemRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
45 changes: 43 additions & 2 deletions tests/js/client/shell/shell-query-dbserver-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function queriesTestSuite () {
'use strict';

return {
setUp: function() {
setUpAll: function() {
arango.reconnect(originalEndpoint, "_system", arango.connectedUser(), "");
db._drop(cn);

Expand All @@ -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() {
Expand Down Expand Up @@ -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);
});
},

};
}
Expand Down