Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94bb6c4

Browse files
Fix overflow danger in SampleHeapTupleVisible(), take 2
28328ec addressed one overflow danger inSampleHeapTupleVisible() but introduced another, albeit a less likelyone. Modify the binary search code to remove this danger.Reported-by: Richard GuoReviewed-by: Richard Guo, Ranier VilelaDiscussion:https://postgr.es/m/CAMbWs4_bE%2BNscChbKWzw6HZOipCUyXfA5133qvoXQ654D3B2gQ%40mail.gmail.com
1 parent38c579b commit94bb6c4

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

‎src/backend/access/heap/heapam_handler.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,11 +2574,8 @@ SampleHeapTupleVisible(TableScanDesc scan, Buffer buffer,
25742574

25752575
if (scan->rs_flags&SO_ALLOW_PAGEMODE)
25762576
{
2577-
uint32start,
2578-
end;
2579-
2580-
if (hscan->rs_ntuples==0)
2581-
return false;
2577+
uint32start=0,
2578+
end=hscan->rs_ntuples;
25822579

25832580
/*
25842581
* In pageatatime mode, heap_prepare_pagescan() already did visibility
@@ -2589,18 +2586,15 @@ SampleHeapTupleVisible(TableScanDesc scan, Buffer buffer,
25892586
* in increasing order, but it's not clear that there would be enough
25902587
* gain to justify the restriction.
25912588
*/
2592-
start=0;
2593-
end=hscan->rs_ntuples-1;
2594-
2595-
while (start <=end)
2589+
while (start<end)
25962590
{
2597-
uint32mid=(start+end) /2;
2591+
uint32mid=start+(end-start) /2;
25982592
OffsetNumbercuroffset=hscan->rs_vistuples[mid];
25992593

26002594
if (tupoffset==curoffset)
26012595
return true;
26022596
elseif (tupoffset<curoffset)
2603-
end=mid-1;
2597+
end=mid;
26042598
else
26052599
start=mid+1;
26062600
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp