public inbox for [email protected]help / color / mirror / Atom feed
pgsql: Fix mis-rounding and overflow hazards in date_bin(). 4+ messages / 1 participants [nested] [flat]
* pgsql: Fix mis-rounding and overflow hazards in date_bin(). @ 2024-02-28 19:02 Tom Lane <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2024-02-28 19:02 UTC (permalink / raw) To: [email protected] Fix mis-rounding and overflow hazards in date_bin(). In the case where the target timestamp is before the origin timestamp and their difference is already an exact multiple of the stride, the code incorrectly subtracted the stride anyway. Also detect several integer-overflow cases that previously produced bogus results. (The submitted patch tried to avoid overflow, but I'm not convinced it's right, and problematic cases are so far out of the plausibly-useful range that they don't seem worth sweating over. Let's just use overflow-detecting arithmetic and throw errors.) timestamp_bin() and timestamptz_bin() are basically identical and so had identical bugs. Fix both. Report and patch by Moaaz Assali, adjusted some by me. Back-patch to v14 where date_bin() was introduced. Discussion: https://postgr.es/m/CALkF+nvtuas-2kydG-WfofbRSJpyODAJWun==W-yO5j2R4meqA@mail.gmail.com Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/fe3b1b575e24748ddb9b3b67394fa10c279090ac Modified Files -------------- src/backend/utils/adt/timestamp.c | 72 +++++++++++++++++++++++-------- src/test/regress/expected/timestamp.out | 14 ++++++ src/test/regress/expected/timestamptz.out | 14 ++++++ src/test/regress/sql/timestamp.sql | 8 ++++ src/test/regress/sql/timestamptz.sql | 8 ++++ 5 files changed, 97 insertions(+), 19 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix mis-rounding and overflow hazards in date_bin(). @ 2024-02-28 19:02 Tom Lane <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2024-02-28 19:02 UTC (permalink / raw) To: [email protected] Fix mis-rounding and overflow hazards in date_bin(). In the case where the target timestamp is before the origin timestamp and their difference is already an exact multiple of the stride, the code incorrectly subtracted the stride anyway. Also detect several integer-overflow cases that previously produced bogus results. (The submitted patch tried to avoid overflow, but I'm not convinced it's right, and problematic cases are so far out of the plausibly-useful range that they don't seem worth sweating over. Let's just use overflow-detecting arithmetic and throw errors.) timestamp_bin() and timestamptz_bin() are basically identical and so had identical bugs. Fix both. Report and patch by Moaaz Assali, adjusted some by me. Back-patch to v14 where date_bin() was introduced. Discussion: https://postgr.es/m/CALkF+nvtuas-2kydG-WfofbRSJpyODAJWun==W-yO5j2R4meqA@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/d163fdbfea82a5a578de5bc6392ae84c590bb454 Modified Files -------------- src/backend/utils/adt/timestamp.c | 72 +++++++++++++++++++++++-------- src/test/regress/expected/timestamp.out | 14 ++++++ src/test/regress/expected/timestamptz.out | 14 ++++++ src/test/regress/sql/timestamp.sql | 8 ++++ src/test/regress/sql/timestamptz.sql | 8 ++++ 5 files changed, 97 insertions(+), 19 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix mis-rounding and overflow hazards in date_bin(). @ 2024-02-28 19:02 Tom Lane <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2024-02-28 19:02 UTC (permalink / raw) To: [email protected] Fix mis-rounding and overflow hazards in date_bin(). In the case where the target timestamp is before the origin timestamp and their difference is already an exact multiple of the stride, the code incorrectly subtracted the stride anyway. Also detect several integer-overflow cases that previously produced bogus results. (The submitted patch tried to avoid overflow, but I'm not convinced it's right, and problematic cases are so far out of the plausibly-useful range that they don't seem worth sweating over. Let's just use overflow-detecting arithmetic and throw errors.) timestamp_bin() and timestamptz_bin() are basically identical and so had identical bugs. Fix both. Report and patch by Moaaz Assali, adjusted some by me. Back-patch to v14 where date_bin() was introduced. Discussion: https://postgr.es/m/CALkF+nvtuas-2kydG-WfofbRSJpyODAJWun==W-yO5j2R4meqA@mail.gmail.com Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/17db5436efb063fc43d0f539bc2f1d0f46fda3d8 Modified Files -------------- src/backend/utils/adt/timestamp.c | 72 +++++++++++++++++++++++-------- src/test/regress/expected/timestamp.out | 14 ++++++ src/test/regress/expected/timestamptz.out | 14 ++++++ src/test/regress/sql/timestamp.sql | 8 ++++ src/test/regress/sql/timestamptz.sql | 8 ++++ 5 files changed, 97 insertions(+), 19 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix mis-rounding and overflow hazards in date_bin(). @ 2024-02-28 19:02 Tom Lane <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Tom Lane @ 2024-02-28 19:02 UTC (permalink / raw) To: [email protected] Fix mis-rounding and overflow hazards in date_bin(). In the case where the target timestamp is before the origin timestamp and their difference is already an exact multiple of the stride, the code incorrectly subtracted the stride anyway. Also detect several integer-overflow cases that previously produced bogus results. (The submitted patch tried to avoid overflow, but I'm not convinced it's right, and problematic cases are so far out of the plausibly-useful range that they don't seem worth sweating over. Let's just use overflow-detecting arithmetic and throw errors.) timestamp_bin() and timestamptz_bin() are basically identical and so had identical bugs. Fix both. Report and patch by Moaaz Assali, adjusted some by me. Back-patch to v14 where date_bin() was introduced. Discussion: https://postgr.es/m/CALkF+nvtuas-2kydG-WfofbRSJpyODAJWun==W-yO5j2R4meqA@mail.gmail.com Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/db8855b66f5cfd9761b1763fdc6b8d93179607df Modified Files -------------- src/backend/utils/adt/timestamp.c | 72 +++++++++++++++++++++++-------- src/test/regress/expected/timestamp.out | 14 ++++++ src/test/regress/expected/timestamptz.out | 14 ++++++ src/test/regress/sql/timestamp.sql | 8 ++++ src/test/regress/sql/timestamptz.sql | 8 ++++ 5 files changed, 97 insertions(+), 19 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-02-28 19:02 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2024-02-28 19:02 pgsql: Fix mis-rounding and overflow hazards in date_bin(). Tom Lane <[email protected]> 2024-02-28 19:02 pgsql: Fix mis-rounding and overflow hazards in date_bin(). Tom Lane <[email protected]> 2024-02-28 19:02 pgsql: Fix mis-rounding and overflow hazards in date_bin(). Tom Lane <[email protected]> 2024-02-28 19:02 pgsql: Fix mis-rounding and overflow hazards in date_bin(). Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox