Skip to content

Fix overflow for very big years (>2*10^9) - #2551

Merged
vitaut merged 1 commit into
fmtlib:masterfrom
phprus:optimize-tm-formatting-3-ub-1
Oct 19, 2021
Merged

vitaut merged 1 commit into
fmtlib:masterfrom
phprus:optimize-tm-formatting-3-ub-1

Conversation

@phprus

@phprus phprus commented Oct 17, 2021

Copy link
Copy Markdown
Contributor

Information: #2544 (comment)

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Could you add a unit test that check that we don't have an overflow?

Comment thread include/fmt/chrono.h Outdated
@phprus

phprus commented Oct 17, 2021

Copy link
Copy Markdown
Contributor Author

I don't know how to write a test. The algorithm requires the correct values of tm_yday and tm_wday, and they calculated is not be simple for the distant future.
I'm not sure if the strftime function for such arguments will return the correct result.

@phprus
phprus force-pushed the optimize-tm-formatting-3-ub-1 branch from 52efa44 to e935b50 Compare October 17, 2021 16:47
@vitaut
vitaut merged commit 7463c83 into fmtlib:master Oct 19, 2021
@vitaut

vitaut commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

For future reference this was the problematic input from fuzzer:

  char tz[] = "LMT";
  auto t = std::tm{.tm_sec = 41,
                   .tm_min = 33,
                   .tm_hour = 4,
                   .tm_mday = 21,
                   .tm_mon = 1,
                   .tm_year = -1996868082,
                   .tm_wday = 6,
                   .tm_yday = 51,
                   .tm_isdst = 0,
                   .tm_gmtoff = -28378,
                   .tm_zone = tz};
  fmt::print("{:%V}", t);

@vitaut vitaut changed the title Fix overflow for very bigger years (>2*10^9) Fix overflow for very big years (>2*10^9) Oct 19, 2021
PoetaKodu pushed a commit to pacc-repo/fmt that referenced this pull request Nov 11, 2021
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.

2 participants