postgresql/src/backend/utils/sort
Stephen Frost 273dcd1628 Ensure 64bit arithmetic when calculating tapeSpace
In tuplesort.c:inittapes(), we calculate tapeSpace by first figuring
out how many 'tapes' we can use (maxTapes) and then multiplying the
result by the tape buffer overhead for each.  Unfortunately, when
we are on a system with an 8-byte long, we allow work_mem to be
larger than 2GB and that allows maxTapes to be large enough that the
32bit arithmetic can overflow when multiplied against the buffer
overhead.

When this overflow happens, we end up adding the overflow to the
amount of space available, causing the amount of memory allocated to
be larger than work_mem.

Note that to reach this point, you have to set work mem to at least
24GB and be sorting a set which is at least that size.  Given that a
user who can set work_mem to 24GB could also set it even higher, if
they were looking to run the system out of memory, this isn't
considered a security issue.

This overflow risk was found by the Coverity scanner.

Back-patch to all supported branches, as this issue has existed
since before 8.4.
2013-07-14 16:26:16 -04:00
..
.gitignore Speed up in-memory tuplesorting. 2012-02-15 12:13:32 -05:00
gen_qsort_tuple.pl Run newly-configured perltidy script on Perl files. 2012-07-04 21:47:49 -04:00
logtape.c Update copyrights for 2013 2013-01-01 17:15:01 -05:00
Makefile Fix VPATH builds, broken by my recent commit to speed up tuplesorting. 2012-02-15 15:53:53 -05:00
sortsupport.c Update copyrights for 2013 2013-01-01 17:15:01 -05:00
tuplesort.c Ensure 64bit arithmetic when calculating tapeSpace 2013-07-14 16:26:16 -04:00
tuplestore.c Use type "int64" for memory accounting in tuplesort.c/tuplestore.c. 2013-07-04 23:13:54 -04:00