Skip to content
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

c/tests: avoid ubsan signed integer overflow #24133

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

nvartolomei
Copy link
Contributor

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 nanosecond granularity. When doing that, duration is converted to a common type, nanosecond 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

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.2.x
  • v24.1.x
  • v23.3.x

Release Notes

  • none

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 nanosecond granularity. When doing that, duration is converted to a
common type, nanosecond 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.
@bharathv
Copy link
Contributor

duration is converted to a common type, nanosecond 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).

I'm probably missing something, if common_type(nanos, mills) = nanos, millis should be multiplied by 10^6, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants