pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix float-to-integer coercions to handle edge cases correctly. 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 01:57 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 01:57 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. Per bug #15519 from Victor Petrovykh. This should get back-patched, but first let's see what the buildfarm thinks of it --- I'm not too sure about portability of some of the regression test cases. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/cbdb8b4c0155b2d9679ecd79b886c29c2730b85d Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 52 +++++++++----- src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 7 files changed, 277 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 17:46 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 17:46 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. This back-patches commits cbdb8b4c0 and 452b637d4. In the 9.4 branch, also back-patch the portion of 62e2a8dc2 that added PG_INTnn_MIN and related constants to c.h, so that these functions can rely on them. Per bug #15519 from Victor Petrovykh. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e473e1f2b8f1b64cae0786bbec66d8fb27efb9b1 Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 52 +++++++++----- src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 7 files changed, 277 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 17:46 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 17:46 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. This back-patches commits cbdb8b4c0 and 452b637d4. In the 9.4 branch, also back-patch the portion of 62e2a8dc2 that added PG_INTnn_MIN and related constants to c.h, so that these functions can rely on them. Per bug #15519 from Victor Petrovykh. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c382a2b66909a78982636f3d192e43e8f48bf504 Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 53 ++++++++------- src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 7 files changed, 273 insertions(+), 34 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 17:46 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 17:46 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. This back-patches commits cbdb8b4c0 and 452b637d4. In the 9.4 branch, also back-patch the portion of 62e2a8dc2 that added PG_INTnn_MIN and related constants to c.h, so that these functions can rely on them. Per bug #15519 from Victor Petrovykh. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/93eec1238663beab8521605f08a5937dbd8ec114 Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 53 ++++++++------- src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 7 files changed, 273 insertions(+), 34 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 17:46 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 17:46 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. This back-patches commits cbdb8b4c0 and 452b637d4. In the 9.4 branch, also back-patch the portion of 62e2a8dc2 that added PG_INTnn_MIN and related constants to c.h, so that these functions can rely on them. Per bug #15519 from Victor Petrovykh. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1e78603a54a740f9a40cabec74cc3e1a8634b861 Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 53 ++++++++------- src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 7 files changed, 273 insertions(+), 34 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix float-to-integer coercions to handle edge cases correctly. @ 2018-11-24 17:46 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2018-11-24 17:46 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix float-to-integer coercions to handle edge cases correctly. ftoi4 and its sibling coercion functions did their overflow checks in a way that looked superficially plausible, but actually depended on an assumption that the MIN and MAX comparison constants can be represented exactly in the float4 or float8 domain. That fails in ftoi4, ftoi8, and dtoi8, resulting in a possibility that values near the MAX limit will be wrongly converted (to negative values) when they need to be rejected. Also, because we compared before rounding off the fractional part, the other three functions threw errors for values that really ought to get rounded to the min or max integer value. Fix by doing rint() first (requiring an assumption that it handles NaN and Inf correctly; but dtoi8 and ftoi8 were assuming that already), and by comparing to values that should coerce to float exactly, namely INTxx_MIN and -INTxx_MIN. Also remove some random cosmetic discrepancies between these six functions. This back-patches commits cbdb8b4c0 and 452b637d4. In the 9.4 branch, also back-patch the portion of 62e2a8dc2 that added PG_INTnn_MIN and related constants to c.h, so that these functions can rely on them. Per bug #15519 from Victor Petrovykh. Patch by me; thanks to Andrew Gierth for analysis and discussion. Discussion: https://postgr.es/m/15519-4fc785b483201ff1@postgresql.org Branch ------ REL9_4_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d5231253e3093936e28adc60442841b5ea89e632 Modified Files -------------- src/backend/utils/adt/float.c | 79 +++++++++++++++++++--- src/backend/utils/adt/int8.c | 53 ++++++++------- src/include/c.h | 17 +++++ src/test/regress/expected/float4.out | 49 ++++++++++++++ src/test/regress/expected/float8-small-is-zero.out | 49 ++++++++++++++ src/test/regress/expected/float8.out | 49 ++++++++++++++ src/test/regress/sql/float4.sql | 14 ++++ src/test/regress/sql/float8.sql | 14 ++++ 8 files changed, 290 insertions(+), 34 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2018-11-24 17:46 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-11-24 01:57 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us> 2018-11-24 17:46 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us> 2018-11-24 17:46 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us> 2018-11-24 17:46 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us> 2018-11-24 17:46 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us> 2018-11-24 17:46 pgsql: Fix float-to-integer coercions to handle edge cases correctly. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox