-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Possible value overflow in erts_time_unit_conversion
#8186
Comments
Thanks for your report! As far as I can tell the result is correct: it's supposed to calculate the converted time modulo 2 ** 64. This should not cause issues beyond a certain optimization going away, so you might have run into a bug where some code didn't expect this. How did you discover this? Did something crash? |
I was trying to build Erlang/OTP for ARM64 Windows (#8142). And I found that the testcase, |
…-19036' into maint * john/erts/fix-win64-monotonic-time-overflow/GH-8186/OTP-19036: erts: Fix overflow when calculating monotonic start_offset
…-19036' into maint-24 * john/erts/fix-win64-monotonic-time-overflow/GH-8186/OTP-19036: erts: Fix overflow when calculating monotonic start_offset
…-19036' into maint-26 * john/erts/fix-win64-monotonic-time-overflow/GH-8186/OTP-19036: erts: Fix overflow when calculating monotonic start_offset
…-19036' into maint-25 * john/erts/fix-win64-monotonic-time-overflow/GH-8186/OTP-19036: erts: Fix overflow when calculating monotonic start_offset
Thanks again for your report, we merged a fix three weeks ago but I forgot to make a note of it here. :) |
Thank you very much for the update! ;) |
Describe the bug
The result of the converted time can exceed the maximum possible value of
uint64_t
.To Reproduce
For an instance, on my ARM64 Windows machine (this issue can happen on any machine that meets the following conditions), it doesn't have the macro
ERTS_COMPILE_TIME_MONOTONIC_TIME_UNIT
defined, and theERTS_MONOTONIC_TIME_UNIT
is initialised to24000000
inerts_init_sys_time_sup
otp/erts/emulator/beam/erl_time_sup.c
Lines 917 to 925 in 51f7331
The converted value using nano seconds as the time unit can overflow in
otp/erts/emulator/beam/erl_time_sup.c
Lines 1019 to 1022 in 51f7331
Let's say the
abs_native_offset
is576460752312000000
, the above code is equivalent toThe
erts_time_unit_conversion
is expecting to return24019198012999999488
(btw it's impossible because this value cannot be representable using auint64_t
)In this case, in
erts_time_unit_conversion
,high
will be5592405333
(16#1_4D55_5555
) before left shift 32bits, which will overflow after the bit shift operation.otp/erts/emulator/beam/erl_time.h
Lines 210 to 211 in 51f7331
Expected behavior
erts_time_unit_conversion
can handle large integers without overflow.Affected versions
Tested on OTP 27.0-rc1. But this issue should exist in all OTP versions.
Additional context
poc.c
The text was updated successfully, but these errors were encountered: