postgresql/contrib/intarray
Andrew Gierth 757c5182f2 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
2018-11-24 08:48:36 +00:00
..
bench Don't fall off the end of perl functions 2018-05-27 09:08:42 -04:00
data
expected Fix yet more problems with incorrectly-constructed zero-length arrays. 2018-07-09 14:28:04 -04:00
sql Fix yet more problems with incorrectly-constructed zero-length arrays. 2018-07-09 14:28:04 -04:00
_int_bool.c Change TRUE/FALSE to true/false 2017-11-08 11:37:28 -05:00
_int_gin.c Change TRUE/FALSE to true/false 2017-11-08 11:37:28 -05:00
_int_gist.c Avoid crashes in contrib/intarray gist__int_ops (bug #15518) 2018-11-24 08:48:36 +00:00
_int_op.c Change TRUE/FALSE to true/false 2017-11-08 11:37:28 -05:00
_int_selfuncs.c Update copyright for 2018 2018-01-02 23:30:12 -05:00
_int_tool.c Avoid crashes in contrib/intarray gist__int_ops (bug #15518) 2018-11-24 08:48:36 +00:00
_int.h
_intbig_gist.c Change TRUE/FALSE to true/false 2017-11-08 11:37:28 -05:00
.gitignore
intarray--1.0--1.1.sql
intarray--1.1--1.2.sql
intarray--1.2.sql
intarray--unpackaged--1.0.sql
intarray.control
Makefile