pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix integer-overflow corner cases in substring() functions.
4+ messages / 1 participants
[nested] [flat]

* pgsql: Fix integer-overflow corner cases in substring() functions.
@ 2021-01-04 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-04 23:33 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix integer-overflow corner cases in substring() functions.

If the substring start index and length overflow when added together,
substring() misbehaved, either throwing a bogus "negative substring
length" error on a case that should succeed, or failing to complain that
a negative length is negative (and instead returning the whole string,
in most cases).  Unsurprisingly, the text, bytea, and bit variants of
the function all had this issue.  Rearrange the logic to ensure that
negative lengths are always rejected, and add an overflow check to
handle the other case.

Also install similar guards into detoast_attr_slice() (nee
heap_tuple_untoast_attr_slice()), since it's far from clear that
no other code paths leading to that function could pass it values
that would overflow.

Patch by myself and Pavel Stehule, per bug #16804 from Rafi Shamim.

Back-patch to v11.  While these bugs are old, the common/int.h
infrastructure for overflow-detecting arithmetic didn't exist before
commit 4d6ad3125, and it doesn't seem like these misbehaviors are bad
enough to justify developing a standalone fix for the older branches.

Discussion: https://postgr.es/m/16804-f4eeeb6c11ba71d4@postgresql.org

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7c98759e0485d26303f2572ce7724b6026fddd9c

Modified Files
--------------
src/backend/access/heap/tuptoaster.c  |  31 ++++++++--
src/backend/utils/adt/varbit.c        |  26 ++++----
src/backend/utils/adt/varlena.c       | 110 ++++++++++++++++++++--------------
src/test/regress/expected/bit.out     |  29 +++++++++
src/test/regress/expected/strings.out |  41 +++++++++++++
src/test/regress/sql/bit.sql          |   8 +++
src/test/regress/sql/strings.sql      |  11 ++++
7 files changed, 195 insertions(+), 61 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix integer-overflow corner cases in substring() functions.
@ 2021-01-04 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-04 23:33 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix integer-overflow corner cases in substring() functions.

If the substring start index and length overflow when added together,
substring() misbehaved, either throwing a bogus "negative substring
length" error on a case that should succeed, or failing to complain that
a negative length is negative (and instead returning the whole string,
in most cases).  Unsurprisingly, the text, bytea, and bit variants of
the function all had this issue.  Rearrange the logic to ensure that
negative lengths are always rejected, and add an overflow check to
handle the other case.

Also install similar guards into detoast_attr_slice() (nee
heap_tuple_untoast_attr_slice()), since it's far from clear that
no other code paths leading to that function could pass it values
that would overflow.

Patch by myself and Pavel Stehule, per bug #16804 from Rafi Shamim.

Back-patch to v11.  While these bugs are old, the common/int.h
infrastructure for overflow-detecting arithmetic didn't exist before
commit 4d6ad3125, and it doesn't seem like these misbehaviors are bad
enough to justify developing a standalone fix for the older branches.

Discussion: https://postgr.es/m/16804-f4eeeb6c11ba71d4@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4bd3fad80e5c3bd107583dd9d32d4a47c045a3ec

Modified Files
--------------
src/backend/access/common/detoast.c   |  33 +++++++---
src/backend/utils/adt/varbit.c        |  26 ++++----
src/backend/utils/adt/varlena.c       | 110 ++++++++++++++++++++--------------
src/test/regress/expected/bit.out     |  29 +++++++++
src/test/regress/expected/strings.out |  41 +++++++++++++
src/test/regress/sql/bit.sql          |   8 +++
src/test/regress/sql/strings.sql      |  11 ++++
7 files changed, 195 insertions(+), 63 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix integer-overflow corner cases in substring() functions.
@ 2021-01-04 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-04 23:33 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix integer-overflow corner cases in substring() functions.

If the substring start index and length overflow when added together,
substring() misbehaved, either throwing a bogus "negative substring
length" error on a case that should succeed, or failing to complain that
a negative length is negative (and instead returning the whole string,
in most cases).  Unsurprisingly, the text, bytea, and bit variants of
the function all had this issue.  Rearrange the logic to ensure that
negative lengths are always rejected, and add an overflow check to
handle the other case.

Also install similar guards into detoast_attr_slice() (nee
heap_tuple_untoast_attr_slice()), since it's far from clear that
no other code paths leading to that function could pass it values
that would overflow.

Patch by myself and Pavel Stehule, per bug #16804 from Rafi Shamim.

Back-patch to v11.  While these bugs are old, the common/int.h
infrastructure for overflow-detecting arithmetic didn't exist before
commit 4d6ad3125, and it doesn't seem like these misbehaviors are bad
enough to justify developing a standalone fix for the older branches.

Discussion: https://postgr.es/m/16804-f4eeeb6c11ba71d4@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9e7d87ca84b91b0c6d8cb052bb6193881f6861fb

Modified Files
--------------
src/backend/access/common/detoast.c   |  33 +++++++---
src/backend/utils/adt/varbit.c        |  26 ++++----
src/backend/utils/adt/varlena.c       | 110 ++++++++++++++++++++--------------
src/test/regress/expected/bit.out     |  29 +++++++++
src/test/regress/expected/strings.out |  41 +++++++++++++
src/test/regress/sql/bit.sql          |   8 +++
src/test/regress/sql/strings.sql      |  11 ++++
7 files changed, 195 insertions(+), 63 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* pgsql: Fix integer-overflow corner cases in substring() functions.
@ 2021-01-04 23:33  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-04 23:33 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix integer-overflow corner cases in substring() functions.

If the substring start index and length overflow when added together,
substring() misbehaved, either throwing a bogus "negative substring
length" error on a case that should succeed, or failing to complain that
a negative length is negative (and instead returning the whole string,
in most cases).  Unsurprisingly, the text, bytea, and bit variants of
the function all had this issue.  Rearrange the logic to ensure that
negative lengths are always rejected, and add an overflow check to
handle the other case.

Also install similar guards into detoast_attr_slice() (nee
heap_tuple_untoast_attr_slice()), since it's far from clear that
no other code paths leading to that function could pass it values
that would overflow.

Patch by myself and Pavel Stehule, per bug #16804 from Rafi Shamim.

Back-patch to v11.  While these bugs are old, the common/int.h
infrastructure for overflow-detecting arithmetic didn't exist before
commit 4d6ad3125, and it doesn't seem like these misbehaviors are bad
enough to justify developing a standalone fix for the older branches.

Discussion: https://postgr.es/m/16804-f4eeeb6c11ba71d4@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/50a420bee0c28595974a07a0f2175d677fb6a642

Modified Files
--------------
src/backend/access/heap/tuptoaster.c  |  27 ++++++++-
src/backend/utils/adt/varbit.c        |  26 ++++----
src/backend/utils/adt/varlena.c       | 110 ++++++++++++++++++++--------------
src/test/regress/expected/bit.out     |  29 +++++++++
src/test/regress/expected/strings.out |  43 ++++++++++++-
src/test/regress/sql/bit.sql          |   8 +++
src/test/regress/sql/strings.sql      |  13 +++-
7 files changed, 195 insertions(+), 61 deletions(-)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-01-04 23:33 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04 23:33 pgsql: Fix integer-overflow corner cases in substring() functions. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-04 23:33 pgsql: Fix integer-overflow corner cases in substring() functions. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-04 23:33 pgsql: Fix integer-overflow corner cases in substring() functions. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-04 23:33 pgsql: Fix integer-overflow corner cases in substring() functions. 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