Skip to content

reject out-of-range timestamps when converting to time_point - #1211

Open
rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:chrono-timestamp-overflow
Open

rajath201 wants to merge 1 commit into
msgpack:cpp_masterfrom
rajath201:chrono-timestamp-overflow

Conversation

@rajath201

Copy link
Copy Markdown

The time_point as/convert adaptors in cpp11/chrono.hpp add std::chrono::seconds(sec) from the wire straight onto the target time_point, so scaling seconds to the Duration's ticks is signed overflow whenever the decoded timestamp doesn't fit. A timestamp96 with tv_sec = INT64_MAX aborts under UBSan (9223372036854775807 * 1000000 in <chrono> on libc++), the largest timestamp64 already overflows a nanosecond clock, and on a picosecond time_point any present-day timestamp32 does.

Route the decode-side additions through detail::checked_add, which range-checks both the scaling and the sum and throws std::overflow_error / std::underflow_error, the same exceptions integral_cast already raises in this adaptor. Floating-point reps keep the old path. The two new tests fail on the current tree and pass with the fix, and the full suite is green with -Werror and UBSan.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant