storage_proxy: fix int overflow in service::abstract_read_executor::execute

exec->_cmd->read_timestamp may be initialized by default to api::min_timestamp,
causing:
  service/storage_proxy.cc:3328:116: runtime error: signed integer overflow: 1577983890961976 - -9223372036854775808 cannot be represented in type 'long int'
  Aborting on shard 1.

Do not optimize cross-dc repair if read_timestamp is missing (or just negative)
We're interested in reads that happen within write_timeout of a write.

Fixes #5556

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
Message-Id: <20200108074021.282339-1-bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2020-01-08 09:40:20 +02:00
committed by Avi Kivity
parent 390c8b9b37
commit 39325cf297

View File

@@ -3323,7 +3323,10 @@ public:
}
exec->on_read_resolved();
} else { // digest mismatch
if (is_datacenter_local(exec->_cl)) {
// Do not optimize cross-dc repair if read_timestamp is missing (or just negative)
// We're interested in reads that happen within write_timeout of a write,
// and comparing a timestamp that is too far causes int overflow (#5556)
if (is_datacenter_local(exec->_cl) && exec->_cmd->read_timestamp >= api::timestamp_type(0)) {
auto write_timeout = exec->_proxy->_db.local().get_config().write_request_timeout_in_ms() * 1000;
auto delta = int64_t(digest_resolver->last_modified()) - int64_t(exec->_cmd->read_timestamp);
if (std::abs(delta) <= write_timeout) {