From 39325cf2976a6b08d77db67f13a67eb239c70679 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Wed, 8 Jan 2020 09:40:20 +0200 Subject: [PATCH] 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 Message-Id: <20200108074021.282339-1-bhalevy@scylladb.com> --- service/storage_proxy.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/storage_proxy.cc b/service/storage_proxy.cc index 4e9f09462d..4eaa7bbcbb 100644 --- a/service/storage_proxy.cc +++ b/service/storage_proxy.cc @@ -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) {