]> granicus.if.org Git - postgresql/commit
Avoid integer overflow while sifting-up a heap in tuplesort.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Jul 2017 17:24:16 +0000 (13:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 12 Jul 2017 17:24:16 +0000 (13:24 -0400)
commit512f67c8d02cc558f9c269cc848b0f0f788c4fe1
tree2cf62974d9698238187536b1695d5236a70d1ad0
parentca906f68f22bf2076349394a5f28caf1f6e6f2f7
Avoid integer overflow while sifting-up a heap in tuplesort.c.

If the number of tuples in the heap exceeds approximately INT_MAX/2,
this loop's calculation "2*i+1" could overflow, resulting in a crash.
Fix it by using unsigned int rather than int for the relevant local
variables; that shouldn't cost anything extra on any popular hardware.
Per bug #14722 from Sergey Koposov.

Original patch by Sergey Koposov, modified by me per a suggestion
from Heikki Linnakangas to use unsigned int not int64.

Back-patch to 9.4, where tuplesort.c grew the ability to sort as many
as INT_MAX tuples in-memory (commit 263865a48).

Discussion: https://postgr.es/m/20170629161637.1478.93109@wrigleys.postgresql.org
src/backend/utils/sort/tuplesort.c