Skip to content

Commit 28328ec

Browse files
Fix overflow danger in SampleHeapTupleVisible()
68d9662 made HeapScanDesc->rs_ntuples unsigned but neglected to change how it was being used in SampleHeapTupleVisible(). Return early if rs_ntuples is 0 to avoid overflowing and incorrectly executing the loop code in SampleHeapTupleVisible(). Reported-by: Ranier Vilela Discussion: https://postgr.es/m/CAEudQAot_xQoZyPZjpj1aBUPrPykY5mOPHGyvfe%3Djz%2BWowdA3A%40mail.gmail.com
1 parent 68d9662 commit 28328ec

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/access/heap/heapam_handler.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,12 @@ SampleHeapTupleVisible(TableScanDesc scan, Buffer buffer,
25772577

25782578
if (scan->rs_flags & SO_ALLOW_PAGEMODE)
25792579
{
2580+
uint32 start,
2581+
end;
2582+
2583+
if (hscan->rs_ntuples == 0)
2584+
return false;
2585+
25802586
/*
25812587
* In pageatatime mode, heap_prepare_pagescan() already did visibility
25822588
* checks, so just look at the info it left in rs_vistuples[].
@@ -2586,12 +2592,12 @@ SampleHeapTupleVisible(TableScanDesc scan, Buffer buffer,
25862592
* in increasing order, but it's not clear that there would be enough
25872593
* gain to justify the restriction.
25882594
*/
2589-
int start = 0,
2590-
end = hscan->rs_ntuples - 1;
2595+
start = 0;
2596+
end = hscan->rs_ntuples - 1;
25912597

25922598
while (start <= end)
25932599
{
2594-
int mid = (start + end) / 2;
2600+
uint32 mid = (start + end) / 2;
25952601
OffsetNumber curoffset = hscan->rs_vistuples[mid];
25962602

25972603
if (tupoffset == curoffset)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy