mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-30 19:46:48 +00:00
Fix runtime error: signed integer overflow introduced by2dc3776407Delta-encoded values may wrap around if the encoded value is less than the base value. This could happen in two places: In the mc-format serialization header itself, where the base values are implicit Cassandra epoch time, and in the sstables data files, where the base values are taken from the encoding_stats (later written to the serialization_header). In these cases, when the calculation is done using signed integer/long we may see "runtime error: signed integer overflow" messages in debug mode (with -fsanitize=undefined / -fsanitize=signed-integer-overflow). Overflow here is expected and harmless since we do not gurantee that neither the base values in the serialization header are greater than or equal to Cassandra's epoch now that the delta-encoded values are always greater than or equal to the respective base values in the serialization header. To prevent these warnings, the subtraction/addition should be done with unsigned (two's complement) arithmetic and the result converted to the signed type. Note that to keep the code simple where possible, when also rely on implicit conversion of signed integers to unsigned when either one of added value is unsigned and the other is signed. Fixes: #4098 Signed-off-by: Benny Halevy <bhalevy@scylladb.com> Message-Id: <20190120142950.15776-1-bhalevy@scylladb.com> (cherry picked from commit844a2de263)