]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix division by zero in _bt_vacuum_needs_cleanup()
authorAlexander Korotkov <akorotkov@postgresql.org>
Mon, 15 Apr 2019 17:20:43 +0000 (20:20 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Mon, 15 Apr 2019 18:52:32 +0000 (21:52 +0300)
Checks inside _bt_vacuum_needs_cleanup() allow division by zero to happen when
metad->btm_last_cleanup_num_heap_tuples == 0.  This commit adjusts the
expression so that no division by zero might happen.

Reported-by: Piotr Stefaniak
Discussion: https://postgr.es/m/DB8PR03MB5931C41F7787A95313F08322F22A0%40DB8PR03MB5931.eurprd03.prod.outlook.com
Reviewed-by: Masahiko Sawada
Backpatch-through: 11

src/backend/access/nbtree/nbtree.c

index e8725fbbe1eec84fc9b8e03092b54d96b3bbd8cd..82fc5b6548bd066819401d1488d7348ae514b3bb 100644 (file)
@@ -833,7 +833,7 @@ _bt_vacuum_needs_cleanup(IndexVacuumInfo *info)
                prev_num_heap_tuples = metad->btm_last_cleanup_num_heap_tuples;
 
                if (cleanup_scale_factor <= 0 ||
-                       prev_num_heap_tuples < 0 ||
+                       prev_num_heap_tuples <= 0 ||
                        (info->num_heap_tuples - prev_num_heap_tuples) /
                        prev_num_heap_tuples >= cleanup_scale_factor)
                        result = true;