Skip to content

Commit

Permalink
Prevent crashes in Timestamp::toGMT (#7351)
Browse files Browse the repository at this point in the history
Summary:
Check seconds in Timestamp::toGMT to avoid crashes when seconds are too large.

See #7350

Pull Request resolved: #7351

Reviewed By: xiaoxmeng

Differential Revision: D50855787

Pulled By: mbasmanova

fbshipit-source-id: 89592ec88362a39bf60154d4408c7603e324be7a
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Nov 1, 2023
1 parent f8d2928 commit aead17d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions velox/type/Timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ Timestamp Timestamp::now() {
void Timestamp::toGMT(const date::time_zone& zone) {
// Magic number -2^39 + 24*3600. This number and any number lower than that
// will cause time_zone::to_sys() to SIGABRT. We don't want that to happen.
if (seconds_ <= (-1096193779200l + 86400l)) {
VELOX_UNSUPPORTED(
"Timestamp out of bound for time zone adjustment {} seconds", seconds_);
}
VELOX_USER_CHECK_GT(
seconds_,
-1096193779200l + 86400l,
"Timestamp seconds out of range for time zone adjustment");

VELOX_USER_CHECK_LE(
seconds_,
kMaxSeconds,
"Timestamp seconds out of range for time zone adjustment");

date::local_time<std::chrono::seconds> localTime{
std::chrono::seconds(seconds_)};
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>
Expand Down

0 comments on commit aead17d

Please sign in to comment.