Skip to content

Ido*sqlConnection#FieldToEscapedString(): don't write out of range time #10058

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

Merged
merged 2 commits into from
Jan 14, 2025

Conversation

Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented May 13, 2024

MySQL's FROM_UNIXTIME() NULLs ts <1970, errors for >2038. Postgres' TO_TIMESTAMP() errors for all ts not between 4713BC - 294276AD.

ref/IP/53323

@Al2Klimov Al2Klimov added bug Something isn't working area/db-ido Database output ref/IP labels May 13, 2024
@cla-bot cla-bot bot added the cla/signed label May 13, 2024
@Al2Klimov
Copy link
Member Author

PING @sciolto

@Al2Klimov
Copy link
Member Author

Same schemes are a must.

@lippserd Icinga/icingadb#221 (comment)

@Al2Klimov Al2Klimov requested a review from lippserd May 13, 2024 15:48
@Al2Klimov Al2Klimov force-pushed the error-timestamp-out-of-range-53323 branch from a98105b to dcf4955 Compare June 5, 2024 13:14
@Al2Klimov Al2Klimov requested a review from yhabteab June 10, 2024 15:47
@Al2Klimov Al2Klimov self-assigned this Aug 20, 2024
@lippserd lippserd removed their request for review August 26, 2024 06:27
@Al2Klimov Al2Klimov force-pushed the error-timestamp-out-of-range-53323 branch from dcf4955 to 34ced89 Compare October 2, 2024 08:17
@Al2Klimov Al2Klimov changed the title IdoPgsqlConnection#FieldToEscapedString(): write out of range time as NULL Ido*sqlConnection#FieldToEscapedString(): don't write out of range time Oct 2, 2024
@Al2Klimov Al2Klimov force-pushed the error-timestamp-out-of-range-53323 branch from 34ced89 to f2f6387 Compare October 2, 2024 08:41
MySQL's FROM_UNIXTIME() NULLs ts <1970, errors for >2038.
Postgres' TO_TIMESTAMP() errors for all ts not between 4713BC - 294276AD.
@Al2Klimov Al2Klimov force-pushed the error-timestamp-out-of-range-53323 branch from f2f6387 to c6f9de5 Compare October 2, 2024 09:59
@Al2Klimov Al2Klimov requested a review from julianbrost October 14, 2024 11:09
@yhabteab yhabteab removed their request for review November 25, 2024 12:30
@Al2Klimov Al2Klimov requested review from oxzi and yhabteab December 3, 2024 09:27
Copy link
Member

@oxzi oxzi left a comment

Choose a reason for hiding this comment

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

Change looks good so far. Maybe we should add a note to the docs stating that IDO on MySQL results in riding into the Epochalypse - regardless of its deprecation state.

std::ostringstream msgbuf;
msgbuf << "FROM_UNIXTIME(" << ts << ")";
msgbuf << "FROM_UNIXTIME(" << std::fixed << std::setprecision(0)
<< std::fmin(std::fmax(ts, 1.0), 2147483647.0) << ")";
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't using std::clamp make this more readable? Same goes for the other change at PostgreSQL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only if we all agree not to backport this to v2.13 which doesn't support C++17.

Copy link
Member

Choose a reason for hiding this comment

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

Seriously, std::clamp shouldn't be a deal breaker for not back porting it. So, to me this should also be fine!

Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't using std::clamp make this more readable?

Depends, my understand was that fmin/fmax was used instead of the regular min/max for handling the dangers of floating point (otherwise, NaN might give you undefined behavior, C++ is fun).

Only if we all agree not to backport this to v2.13 which doesn't support C++17.

General remark on that: one option for such situations would be to make a dedicated commit for adapting the code to make use of newer C++ features that could then just be omitted when backporting.

@Al2Klimov
Copy link
Member Author

To say it with a meme: it "always has been". I mean, if MySQL itself supported ts>2038, we didn't have to limit it to 2038 in this PR.

@yhabteab
Copy link
Member

Maybe we should add a note to the docs stating that IDO on MySQL results in riding into the Epochalypse - regardless of its deprecation state.

Why do you think it's necessary to include this in our documentation? After all, this limit isn't specific to IDO only but the DBMs itself, so doesn’t make sense to me to document such a constraint here. @Al2Klimov please rebase!

@Al2Klimov
Copy link
Member Author

Rebase? Does everything else LGTY?

@yhabteab
Copy link
Member

Rebase? Does everything else LGTY?

Shouldn’t this be a sufficient response to your question? #10058 (review)

@Al2Klimov
Copy link
Member Author

No, because @julianbrost seems to still want to review it.

Also, the last time IIRC, you also explicitly allowed to force merge – that's what I'd do.

@julianbrost julianbrost merged commit 1f047eb into master Jan 14, 2025
26 checks passed
@julianbrost julianbrost deleted the error-timestamp-out-of-range-53323 branch January 14, 2025 08:43
@Al2Klimov Al2Klimov added this to the 2.15.0 milestone Jan 14, 2025
@Al2Klimov Al2Klimov added the backported Fix was included in a bugfix release label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/db-ido Database output backported Fix was included in a bugfix release bug Something isn't working cla/signed ref/IP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants