Skip to content

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

Merged
redboltz merged 1 commit into
msgpack:cpp_masterfrom
rajath201:chrono-timestamp-overflow
Nov 16, 2026
Merged

redboltz merged 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.

@redboltz

Copy link
Copy Markdown
Contributor

Appveyor reported errors.
I've fixed appveyor environment. Could you rebase your PR ?

@rajath201
rajath201 force-pushed the chrono-timestamp-overflow branch from cd4998f to a832770 Compare November 16, 2026 10:48
@rajath201

Copy link
Copy Markdown
Author

Rebased onto the latest cpp_master. No conflicts, and the patch itself is unchanged.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.93%. Comparing base (39cc081) to head (a832770).
⚠️ Report is 40 commits behind head on cpp_master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1211      +/-   ##
==============================================
- Coverage       85.36%   79.93%   -5.44%     
==============================================
  Files              80       80              
  Lines            5099     5821     +722     
  Branches          507      635     +128     
==============================================
+ Hits             4353     4653     +300     
- Misses            746     1168     +422     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@redboltz

Copy link
Copy Markdown
Contributor

@rajath201 , thank you for sending the PR. It looks good to me.

@redboltz
redboltz merged commit bcba271 into msgpack:cpp_master Nov 16, 2026
25 checks passed
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.

3 participants