pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
6+ messages / 1 participants
[nested] [flat]

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e193fb9919234b07210b75bf9dfd436fd2b218b9

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 14 +++++----
2 files changed, 72 insertions(+), 13 deletions(-)



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

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5f11a500fac69da4c3de61bf878d66f73f4fc8d3

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 12 +++++---
2 files changed, 71 insertions(+), 12 deletions(-)



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

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/757c5182f2c42af528386c0419c60c111c678cab

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 14 ++++++---
2 files changed, 73 insertions(+), 12 deletions(-)



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

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2f30b311df1e7532ef46cdb7a3067377fbf572d9

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 12 +++++---
2 files changed, 71 insertions(+), 12 deletions(-)



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

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2e497ed235528314b92a8c6a2cfb4aceb5ba1500

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 14 ++++++---
2 files changed, 73 insertions(+), 12 deletions(-)



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

* pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
@ 2018-11-24 08:53  Andrew Gierth <rhodiumtoad@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Andrew Gierth @ 2018-11-24 08:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Avoid crashes in contrib/intarray gist__int_ops (bug #15518)

1. Integer overflow in internal_size could result in memory corruption
in decompression since a zero-length array would be allocated and then
written to. This leads to crashes or corruption when traversing an
index which has been populated with sufficiently sparse values. Fix by
using int64 for computations and checking for overflow.

2. Integer overflow in g_int_compress could cause pessimal merge
choices, resulting in unnecessarily large ranges (which would in turn
trigger issue 1 above). Fix by using int64 again.

3. Even without overflow, array sizes could become large enough to
cause unexplained memory allocation errors. Fix by capping the sizes
to a safe limit and report actual errors pointing at gist__intbig_ops
as needed.

4. Large inputs to the compression function always consist of large
runs of consecutive integers, and the compression loop was processing
these one at a time in an O(N^2) manner with a lot of overhead. The
expected runtime of this function could easily exceed 6 months for a
single call as a result. Fix by performing a linear-time first pass,
which reduces the worst case to something on the order of seconds.

Backpatch all the way, since this has been wrong forever.

Per bug #15518 from report from irc user "dymk", analysis and patch by
me.

Discussion: https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f0bfc7a2b13a6cd48b6cea253b0e9f918e457c6d

Modified Files
--------------
contrib/intarray/_int_gist.c | 71 +++++++++++++++++++++++++++++++++++++++-----
contrib/intarray/_int_tool.c | 12 +++++---
2 files changed, 71 insertions(+), 12 deletions(-)



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


end of thread, other threads:[~2018-11-24 08:53 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 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>
2018-11-24 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>
2018-11-24 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>
2018-11-24 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>
2018-11-24 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>
2018-11-24 08:53 pgsql: Avoid crashes in contrib/intarray gist__int_ops (bug #15518) Andrew Gierth <rhodiumtoad@postgresql.org>

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