Re: Can rs_cindex be < 0 for bitmap heap scans?
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: Ranier Vilela <ranier.vf@gmail.com>, Dilip Kumar <dilipbalaut@gmail.com>, Pg Hackers <pgsql-hackers@postgresql.org>, Tomas Vondra <tv@fuzzy.cz>,
Tom Lane <tgl@sss.pgh.pa.us>
Date: 2024-12-19T02:50:31Z
Lists: pgsql-hackers
On Thu, Dec 19, 2024 at 8:18 AM Melanie Plageman
<melanieplageman@gmail.com> wrote:
> I pushed the straightforward option for now so that it's fixed.
I think this binary search code now has a risk of underflow. If 'mid'
is calculated as zero, the second 'if' branch will cause 'end' to
underflow.
Maybe we need to do something like below.
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2600,7 +2600,11 @@ SampleHeapTupleVisible(TableScanDesc scan, Buffer buffer,
if (tupoffset == curoffset)
return true;
else if (tupoffset < curoffset)
+ {
+ if (mid == 0)
+ return false;
end = mid - 1;
+ }
else
start = mid + 1;
}
Alternatively, we can revert 'start' and 'end' to signed int as they
were before.
Thanks
Richard
Commits
-
Fix overflow danger in SampleHeapTupleVisible(), take 2
- 94bb6c4410d8 18.0 landed
-
Fix overflow danger in SampleHeapTupleVisible()
- 28328ec87b45 18.0 landed
-
Make rs_cindex and rs_ntuples unsigned
- 68d9662be1c4 18.0 landed