Skip to content

Commit 0b7ba3d

Browse files
committed
pgstatindex: Insert some casts to prevent overflow.
This could cause hash indexes to report greater than 100% free space. Ashutosh Sharma, reviewed by Amit Kapila Discussion: http://postgr.es/m/CAE9k0PnCKfg-ZK1CwGZJPF1yKcG2A=GUgC3BMdNMzLAXVOo4Eg@mail.gmail.com
1 parent ec99dd5 commit 0b7ba3d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

contrib/pgstattuple/pgstatindex.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,14 @@ pgstathashindex(PG_FUNCTION_ARGS)
687687
index_close(rel, AccessShareLock);
688688

689689
/* Count unused pages as free space. */
690-
stats.free_space += stats.unused_pages * stats.space_per_page;
690+
stats.free_space += (uint64) stats.unused_pages * stats.space_per_page;
691691

692692
/*
693693
* Total space available for tuples excludes the metapage and the bitmap
694694
* pages.
695695
*/
696-
total_space = (nblocks - (stats.bitmap_pages + 1)) * stats.space_per_page;
696+
total_space = (uint64) (nblocks - (stats.bitmap_pages + 1)) *
697+
stats.space_per_page;
697698

698699
if (total_space == 0)
699700
free_percent = 0.0;

0 commit comments

Comments
 (0)