Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b79e75d

Browse files
committed
Need defense against oversize index entries in btree CREATE INDEX,
as well as when inserting entries into an existing index.
1 parent 8da88a6 commit b79e75d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/access/nbtree/nbtsort.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* Copyright (c) 1994, Regents of the University of California
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.47 1999/10/17 22:15:04 tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.48 2000/01/08 21:24:49 tgl Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -301,6 +301,23 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti, int flags)
301301
pgspc = PageGetFreeSpace(npage);
302302
btisz = BTITEMSZ(bti);
303303
btisz = MAXALIGN(btisz);
304+
305+
/*
306+
* Check whether the item can fit on a btree page at all.
307+
* (Eventually, we ought to try to apply TOAST methods if not.)
308+
* We actually need to be able to fit three items on every page,
309+
* so restrict any one item to 1/3 the per-page available space.
310+
* Note that at this point, btisz doesn't include the ItemId.
311+
*
312+
* NOTE: similar code appears in _bt_insertonpg() to defend against
313+
* oversize items being inserted into an already-existing index.
314+
* But during creation of an index, we don't go through there.
315+
*/
316+
if (btisz > (PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData))
317+
elog(ERROR, "btree: index item size %d exceeds maximum %d",
318+
btisz,
319+
(PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData));
320+
304321
if (pgspc < btisz)
305322
{
306323
Buffer obuf = nbuf;

0 commit comments

Comments
 (0)