redpanda-data / redpanda

Redpanda is a streaming data platform for developers. Kafka API compatible. 10x faster. No ZooKeeper. No JVM!
https://redpanda.com
9.65k stars 589 forks source link

c/tests: avoid ubsan signed integer overflow #24133

Closed nvartolomei closed 21 hours ago

nvartolomei commented 1 day ago

Before the change ubsan would assert on a signed integer overflow

/vectorized/llvm/bin/../include/c++/v1/__chrono/duration.h:92:79: runtime error: signed integer overflow: 9223372036854775807 * 1000 cannot be represented in type '_Ct' (aka 'long long')
cluster::tx::producer_state_manager::evict_excess_producers() at /vectorized/llvm/bin/../include/c++/v1/__chrono/duration.h:92

The problem lies in that we try to subtract duration from a time_point with microsecond granularity. When doing that, duration is converted to a common type, microsecond representation and the millisecond::max() being already maximum value that can be represented in a long long can't be converted to micros (multiplied by 1000).

Not sure if this is the perfect fix but avoid the problem by initializing the duration with a value that can be later represented as micros.

Backports Required

Release Notes